mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 07:19:18 +01:00
Do not create a new background worker every time the checks are refreshed; queue
a new check on the existing one instead. Moved the background worker to the designer of the class. Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
parent
c2ae0a6069
commit
b08e91a470
@ -46,6 +46,7 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
this.checkBoxViewPrecheckFailuresOnly = new System.Windows.Forms.CheckBox();
|
||||
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
|
||||
this.labelProgress = new System.Windows.Forms.Label();
|
||||
this._worker = new System.ComponentModel.BackgroundWorker();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxIssues)).BeginInit();
|
||||
this.tableLayoutPanel1.SuspendLayout();
|
||||
@ -176,6 +177,14 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
resources.ApplyResources(this.labelProgress, "labelProgress");
|
||||
this.labelProgress.Name = "labelProgress";
|
||||
//
|
||||
// _worker
|
||||
//
|
||||
this._worker.WorkerReportsProgress = true;
|
||||
this._worker.WorkerSupportsCancellation = true;
|
||||
this._worker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.worker_DoWork);
|
||||
this._worker.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.worker_ProgressChanged);
|
||||
this._worker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this._worker_RunWorkerCompleted);
|
||||
//
|
||||
// PatchingWizard_PrecheckPage
|
||||
//
|
||||
this.Controls.Add(this.tableLayoutPanel1);
|
||||
@ -204,6 +213,7 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn ColumnSolution;
|
||||
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
|
||||
private System.Windows.Forms.Label labelProgress;
|
||||
private System.ComponentModel.BackgroundWorker _worker;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -55,10 +55,11 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
|
||||
private readonly object _lock = new object();
|
||||
private readonly object _update_grid_lock = new object();
|
||||
private BackgroundWorker _worker;
|
||||
public List<Host> SelectedServers = new List<Host>();
|
||||
private readonly List<Problem> ProblemsResolvedPreCheck = new List<Problem>();
|
||||
private AsyncAction resolvePrechecksAction;
|
||||
|
||||
private bool _isRecheckQueued;
|
||||
public Dictionary<Pool_update, Dictionary<Host, SR>> SrUploadedUpdates = new Dictionary<Pool_update, Dictionary<Host, SR>>();
|
||||
|
||||
protected List<Pool> SelectedPools
|
||||
@ -162,13 +163,11 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
|
||||
protected void RefreshRechecks()
|
||||
{
|
||||
_worker = null;
|
||||
_worker = new BackgroundWorker();
|
||||
_worker.DoWork += worker_DoWork;
|
||||
_worker.WorkerReportsProgress = true;
|
||||
_worker.WorkerSupportsCancellation = true;
|
||||
_worker.ProgressChanged += worker_ProgressChanged;
|
||||
_worker.RunWorkerCompleted += _worker_RunWorkerCompleted;
|
||||
if (IsCheckInProgress)
|
||||
{
|
||||
_isRecheckQueued = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Patch != null)
|
||||
_worker.RunWorkerAsync(Patch);
|
||||
@ -183,6 +182,12 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
progressBar1.Value = 100;
|
||||
labelProgress.Text = string.Empty;
|
||||
OnPageUpdated();
|
||||
|
||||
if (_isRecheckQueued)
|
||||
{
|
||||
_isRecheckQueued = false;
|
||||
RefreshRechecks();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,7 +225,7 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
|
||||
private bool IsCheckInProgress
|
||||
{
|
||||
get { return _worker != null && _worker.IsBusy; }
|
||||
get { return _worker.IsBusy; }
|
||||
}
|
||||
|
||||
private bool IsResolveActionInProgress
|
||||
@ -271,9 +276,13 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
|
||||
private void worker_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
var bgw = sender as BackgroundWorker;
|
||||
if (bgw == null)
|
||||
return;
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
_worker.ReportProgress(0, null);
|
||||
bgw.ReportProgress(0, null);
|
||||
Program.Invoke(this, () =>
|
||||
{
|
||||
dataGridView1.Rows.Clear();
|
||||
@ -295,7 +304,7 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
|
||||
foreach (var group in groups)
|
||||
{
|
||||
if (_worker.CancellationPending)
|
||||
if (bgw.CancellationPending)
|
||||
{
|
||||
e.Cancel = true;
|
||||
return;
|
||||
@ -303,14 +312,14 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
|
||||
var headerRow = new PreCheckHeaderRow(string.Format(Messages.PATCHING_WIZARD_PRECHECK_STATUS, group.Key));
|
||||
//multiply with 100 first, otherwise the quotient is 0
|
||||
_worker.ReportProgress(doneCheckIndex*100/totalChecks, headerRow);
|
||||
bgw.ReportProgress(doneCheckIndex * 100 / totalChecks, headerRow);
|
||||
|
||||
PreCheckResult precheckResult = PreCheckResult.OK;
|
||||
var checks = group.Value;
|
||||
|
||||
foreach (var check in checks)
|
||||
{
|
||||
if (_worker.CancellationPending)
|
||||
if (bgw.CancellationPending)
|
||||
{
|
||||
e.Cancel = true;
|
||||
return;
|
||||
@ -325,7 +334,7 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
precheckResult = row.PrecheckResult;
|
||||
|
||||
//multiply with 100 first, otherwise the quotient is 0
|
||||
_worker.ReportProgress(doneCheckIndex*100/totalChecks, row);
|
||||
bgw.ReportProgress(doneCheckIndex * 100 / totalChecks, row);
|
||||
}
|
||||
}
|
||||
|
||||
@ -573,8 +582,7 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
public override void PageCancelled()
|
||||
{
|
||||
DeregisterEventHandlers();
|
||||
if (_worker != null)
|
||||
_worker.CancelAsync();
|
||||
_worker.CancelAsync();
|
||||
if (resolvePrechecksAction != null && !resolvePrechecksAction.IsCompleted)
|
||||
resolvePrechecksAction.Cancel();
|
||||
}
|
||||
@ -582,11 +590,8 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
|
||||
{
|
||||
DeregisterEventHandlers();
|
||||
if (direction == PageLoadedDirection.Back && _worker != null)
|
||||
{
|
||||
if (direction == PageLoadedDirection.Back)
|
||||
_worker.CancelAsync();
|
||||
_worker = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool EnablePrevious()
|
||||
|
@ -429,6 +429,9 @@
|
||||
<data name=">>labelPrechecksFirstLine.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<metadata name="_worker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
@ -456,6 +459,12 @@
|
||||
<data name=">>ColumnSolution.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>_worker.Name" xml:space="preserve">
|
||||
<value>_worker</value>
|
||||
</data>
|
||||
<data name=">>_worker.Type" xml:space="preserve">
|
||||
<value>System.ComponentModel.BackgroundWorker, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>$this.Name" xml:space="preserve">
|
||||
<value>PatchingWizard_PrecheckPage</value>
|
||||
</data>
|
||||
|
@ -75,7 +75,7 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
|
||||
|
||||
private void connection_ConnectionChanged(object sender, EventArgs eventArgs)
|
||||
{
|
||||
Program.Invoke(Program.MainWindow, RefreshRechecks);
|
||||
Program.Invoke(this, RefreshRechecks);
|
||||
}
|
||||
|
||||
protected override void PageLoadedCore(PageLoadedDirection direction)
|
||||
|
Loading…
Reference in New Issue
Block a user