mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 07:19:18 +01:00
Merge pull request #776 from MihaelaStoica/CP-14472
CP-14472: Remove the lock in the License Manager and ensure that all the updates are done on the main thread.
This commit is contained in:
commit
04e5820db2
@ -61,15 +61,13 @@ namespace XenAdmin.Controls.CheckableDataGridView
|
||||
}
|
||||
|
||||
protected readonly List<CheckableDataGridViewRow> storedRows = new List<CheckableDataGridViewRow>();
|
||||
protected readonly object StoredRowsLock = new object();
|
||||
|
||||
public void ClearAllRows()
|
||||
{
|
||||
lock (StoredRowsLock)
|
||||
{
|
||||
storedRows.ForEach(r => r.Dispose());
|
||||
storedRows.Clear();
|
||||
}
|
||||
Program.AssertOnEventThread();
|
||||
storedRows.ForEach(r => r.Dispose());
|
||||
storedRows.Clear();
|
||||
|
||||
View.DrawAllRowsAsCleared();
|
||||
}
|
||||
|
||||
@ -82,10 +80,8 @@ namespace XenAdmin.Controls.CheckableDataGridView
|
||||
{
|
||||
foreach (CheckableDataGridViewRow cRow in rows)
|
||||
{
|
||||
lock (StoredRowsLock)
|
||||
{
|
||||
storedRows.Add(cRow);
|
||||
}
|
||||
Program.AssertOnEventThread();
|
||||
storedRows.Add(cRow);
|
||||
cRow.CellDataUpdated += cRow_CellDataUpdated;
|
||||
IXenObject xenObject = GetXenObject(cRow);
|
||||
if (xenObject != null && xenObject.Connection != null)
|
||||
@ -201,20 +197,21 @@ namespace XenAdmin.Controls.CheckableDataGridView
|
||||
return;
|
||||
|
||||
int indexToUpdate;
|
||||
lock (StoredRowsLock)
|
||||
|
||||
Program.AssertOnEventThread();
|
||||
|
||||
indexToUpdate = ReplaceStoredRow(toUpdate);
|
||||
|
||||
if (indexToUpdate >= storedRows.Count || indexToUpdate < 0)
|
||||
{
|
||||
indexToUpdate = ReplaceStoredRow(toUpdate);
|
||||
|
||||
if (indexToUpdate >= storedRows.Count || indexToUpdate < 0)
|
||||
{
|
||||
log.DebugFormat("Could not update row '{0}'; Stored rows contain '{1}' items", indexToUpdate,
|
||||
storedRows.Count);
|
||||
return;
|
||||
}
|
||||
|
||||
View.DrawUpdatedRow(storedRows[indexToUpdate].CellText, storedRows[indexToUpdate].CellDataLoaded,
|
||||
storedRows[indexToUpdate].Disabled, indexToUpdate);
|
||||
log.DebugFormat("Could not update row '{0}'; Stored rows contain '{1}' items", indexToUpdate,
|
||||
storedRows.Count);
|
||||
return;
|
||||
}
|
||||
|
||||
View.DrawUpdatedRow(storedRows[indexToUpdate].CellText, storedRows[indexToUpdate].CellDataLoaded,
|
||||
storedRows[indexToUpdate].Disabled, indexToUpdate);
|
||||
|
||||
View.TriggerRowUpdatedEvent(indexToUpdate, refreshGrid);
|
||||
}
|
||||
|
||||
@ -288,12 +285,12 @@ namespace XenAdmin.Controls.CheckableDataGridView
|
||||
if(rowIndex < 0 || rowIndex >= storedRows.Count)
|
||||
return;
|
||||
|
||||
lock (StoredRowsLock)
|
||||
{
|
||||
storedRows[rowIndex].DisabledReason = information;
|
||||
storedRows[rowIndex].Disabled = disabled;
|
||||
storedRows[rowIndex].LockDisabledState = disabled;
|
||||
}
|
||||
Program.AssertOnEventThread();
|
||||
|
||||
storedRows[rowIndex].DisabledReason = information;
|
||||
storedRows[rowIndex].Disabled = disabled;
|
||||
storedRows[rowIndex].LockDisabledState = disabled;
|
||||
|
||||
View.DrawSetRowInformation(rowIndex, information);
|
||||
View.DrawRowAsDisabled(disabled, rowIndex);
|
||||
View.DrawRowAsLocked(disabled, rowIndex);
|
||||
|
@ -99,33 +99,32 @@ namespace XenAdmin.Controls
|
||||
if (comparer == null || columnIndex < 0)
|
||||
return;
|
||||
|
||||
lock (StoredRowsLock)
|
||||
Program.AssertOnEventThread();
|
||||
|
||||
View.SuspendDrawing();
|
||||
try
|
||||
{
|
||||
View.SuspendDrawing();
|
||||
try
|
||||
{
|
||||
View.DrawAllRowsAsClearedMW();
|
||||
storedRows.Sort(comparer);
|
||||
View.DrawAllRowsAsClearedMW();
|
||||
storedRows.Sort(comparer);
|
||||
|
||||
if(CurrentSortDirection == SortDirection.Descending)
|
||||
storedRows.Reverse();
|
||||
if(CurrentSortDirection == SortDirection.Descending)
|
||||
storedRows.Reverse();
|
||||
|
||||
foreach (CheckableDataGridViewRow row in storedRows)
|
||||
{
|
||||
View.DrawRowMW(row);
|
||||
LicenseDataGridViewRow lRow = row as LicenseDataGridViewRow;
|
||||
if (lRow == null)
|
||||
continue;
|
||||
LicenseView.DrawStatusIcon(row.Index, lRow.RowStatus);
|
||||
if (row.Highlighted)
|
||||
View.DrawRowAsHighlightedMW(true, row.Index);
|
||||
}
|
||||
}
|
||||
finally
|
||||
foreach (CheckableDataGridViewRow row in storedRows)
|
||||
{
|
||||
View.ResumeDrawing();
|
||||
View.DrawRowMW(row);
|
||||
LicenseDataGridViewRow lRow = row as LicenseDataGridViewRow;
|
||||
if (lRow == null)
|
||||
continue;
|
||||
LicenseView.DrawStatusIcon(row.Index, lRow.RowStatus);
|
||||
if (row.Highlighted)
|
||||
View.DrawRowAsHighlightedMW(true, row.Index);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
View.ResumeDrawing();
|
||||
}
|
||||
}
|
||||
|
||||
private IComparer<CheckableDataGridViewRow> ComparerForColumn(int index)
|
||||
|
@ -83,10 +83,10 @@ namespace XenAdmin.Dialogs
|
||||
if (RowShouldBeExpanded(XenObject) && DataGridView is LicenseCheckableDataGridView)
|
||||
{
|
||||
refreshing = true;
|
||||
TriggerRefreshAllEvent();
|
||||
Program.Invoke(Program.MainWindow, TriggerRefreshAllEvent);
|
||||
}
|
||||
else
|
||||
TriggerCellTextUpdatedEvent();
|
||||
Program.Invoke(Program.MainWindow, TriggerCellTextUpdatedEvent);
|
||||
}
|
||||
|
||||
public static bool RowShouldBeExpanded(IXenObject xenObject)
|
||||
|
Loading…
Reference in New Issue
Block a user