Fluid UI by updating sensors in a background thread. (#626)
* On computers with lots of devices/sensors, the timer update routine will cause a performance hit on the main window redraw when moving it around. This commit address the issue by moving the timer routine to a backgroundworker object that does the work in an async manner (thread). * White spaces. * White spaces. * Keep the ui redraw in the main thread to prevent breaking the tray context menu for the instance.
This commit is contained in:
+2
@@ -126,6 +126,7 @@ namespace LibreHardwareMonitor.UI
|
||||
this.splitContainer = new LibreHardwareMonitor.UI.SplitContainerAdv();
|
||||
this.treeView = new Aga.Controls.Tree.TreeViewAdv();
|
||||
this.psuMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.backgroundUpdater = new System.ComponentModel.BackgroundWorker();
|
||||
this.mainMenu.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
|
||||
this.splitContainer.Panel1.SuspendLayout();
|
||||
@@ -969,6 +970,7 @@ namespace LibreHardwareMonitor.UI
|
||||
private ToolStripRadioButtonMenuItem timeWindow24hMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem authWebServerMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem psuMenuItem;
|
||||
private System.ComponentModel.BackgroundWorker backgroundUpdater;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -163,6 +163,7 @@ namespace LibreHardwareMonitor.UI
|
||||
_computer.HardwareRemoved += HardwareRemoved;
|
||||
_computer.Open();
|
||||
|
||||
backgroundUpdater.DoWork += BackgroundUpdater_DoWork;
|
||||
timer.Enabled = true;
|
||||
|
||||
UserOption showHiddenSensors = new UserOption("hiddenMenuItem", false, hiddenMenuItem, _settings);
|
||||
@@ -377,6 +378,17 @@ namespace LibreHardwareMonitor.UI
|
||||
Microsoft.Win32.SystemEvents.PowerModeChanged += PowerModeChanged;
|
||||
}
|
||||
|
||||
private void BackgroundUpdater_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
_computer.Accept(_updateVisitor);
|
||||
|
||||
if (_logSensors != null && _logSensors.Value && _delayCount >= 4)
|
||||
_logger.Log();
|
||||
|
||||
if (_delayCount < 4)
|
||||
_delayCount++;
|
||||
}
|
||||
|
||||
private void PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.Mode == Microsoft.Win32.PowerModes.Resume)
|
||||
@@ -636,19 +648,14 @@ namespace LibreHardwareMonitor.UI
|
||||
|
||||
private void Timer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
_computer.Accept(_updateVisitor);
|
||||
|
||||
treeView.Invalidate();
|
||||
_plotPanel.InvalidatePlot();
|
||||
_systemTray.Redraw();
|
||||
_gadget?.Redraw();
|
||||
_wmiProvider?.Update();
|
||||
|
||||
if (_logSensors != null && _logSensors.Value && _delayCount >= 4)
|
||||
_logger.Log();
|
||||
|
||||
if (_delayCount < 4)
|
||||
_delayCount++;
|
||||
if (!backgroundUpdater.IsBusy)
|
||||
backgroundUpdater.RunWorkerAsync();
|
||||
|
||||
RestoreCollapsedNodeState(treeView);
|
||||
}
|
||||
@@ -742,6 +749,8 @@ namespace LibreHardwareMonitor.UI
|
||||
if (_runWebServer.Value)
|
||||
Server.Quit();
|
||||
_systemTray.Dispose();
|
||||
timer.Dispose();
|
||||
backgroundUpdater.Dispose();
|
||||
|
||||
Application.Exit();
|
||||
}
|
||||
|
||||
@@ -126,6 +126,9 @@
|
||||
<metadata name="timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>293, 17</value>
|
||||
</metadata>
|
||||
<metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>483, 17</value>
|
||||
</metadata>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
|
||||
Reference in New Issue
Block a user