Skip to content

Commit bdafcd9

Browse files
authored
Implemented storage update interval at the UI side (#1706)
* Minor refactoring for #1699 * Implemented storage update interval for the UI * Revert "Implemented storage update interval for the UI" This reverts commit 977ff2f5518d420e35cadad17054f4e69c260df1. * Revert "Minor refactoring for #1699" This reverts commit 923f6d6f636a2a10ff44b8c23f84e8985ccbf667. * Made update interval configurable for storage devices * Changed label text m to min for consistency * Revised 8e6c669 as requested * ATA Update interval defaults to 1s in the UI * Simplified storage update interval menu
1 parent 56a7fc1 commit bdafcd9

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

LibreHardwareMonitor/UI/MainForm.Designer.cs

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LibreHardwareMonitor/UI/MainForm.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Aga.Controls.Tree;
1616
using Aga.Controls.Tree.NodeControls;
1717
using LibreHardwareMonitor.Hardware;
18+
using LibreHardwareMonitor.Hardware.Storage;
1819
using LibreHardwareMonitor.UI.Themes;
1920
using LibreHardwareMonitor.Utilities;
2021
using LibreHardwareMonitor.Wmi;
@@ -30,6 +31,7 @@ public sealed partial class MainForm : Form
3031
private readonly Logger _logger;
3132
private readonly UserRadioGroup _loggingInterval;
3233
private readonly UserRadioGroup _updateInterval;
34+
private readonly UserOption _throttleAtaUpdate;
3335
private readonly UserOption _logSensors;
3436
private readonly UserOption _minimizeOnClose;
3537
private readonly UserOption _minimizeToTray;
@@ -374,6 +376,21 @@ public MainForm()
374376
}
375377
};
376378

379+
_throttleAtaUpdate = new UserOption("throttleAtaUpdateMenuItem", false, throttleAtaUpdateMenuItem, _settings);
380+
_throttleAtaUpdate.Changed += (sender, e) =>
381+
{
382+
switch (_throttleAtaUpdate.Value)
383+
{
384+
case true:
385+
AtaStorage.ThrottleInterval = TimeSpan.FromSeconds(30);
386+
break;
387+
388+
case false:
389+
AtaStorage.ThrottleInterval = TimeSpan.Zero;
390+
break;
391+
}
392+
};
393+
377394
_sensorValuesTimeWindow = new UserRadioGroup("sensorValuesTimeWindow",
378395
10,
379396
new[]

LibreHardwareMonitorLib/Hardware/Storage/ATAStorage.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public abstract class AtaStorage : AbstractStorage
2222

2323
private IDictionary<SmartAttribute, Sensor> _sensors;
2424

25+
private static TimeSpan _throttleInterval = TimeSpan.Zero;
26+
private DateTime _lastUpdate = DateTime.MinValue;
27+
2528
/// <summary>
2629
/// Gets the SMART data.
2730
/// </summary>
@@ -187,10 +190,28 @@ protected sealed override void CreateSensors()
187190
base.CreateSensors();
188191
}
189192

193+
public static TimeSpan ThrottleInterval
194+
{
195+
get
196+
{
197+
return _throttleInterval;
198+
}
199+
set
200+
{
201+
_throttleInterval = value;
202+
}
203+
}
204+
190205
protected virtual void UpdateAdditionalSensors(Kernel32.SMART_ATTRIBUTE[] values) { }
191206

192207
protected override void UpdateSensors()
193208
{
209+
if (DateTime.UtcNow - _lastUpdate < ThrottleInterval)
210+
{
211+
return;
212+
}
213+
_lastUpdate = DateTime.UtcNow;
214+
194215
if (Smart.IsValid)
195216
{
196217
Kernel32.SMART_ATTRIBUTE[] smartAttributes = Smart.ReadSmartData();
@@ -289,4 +310,4 @@ public override void Close()
289310
Smart.Close();
290311
base.Close();
291312
}
292-
}
313+
}

0 commit comments

Comments
 (0)