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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user