11using System . Collections . Generic ;
2- using System . Timers ;
2+ using System . Threading . Tasks ;
33using RAMSPDToolkit . I2CSMBus ;
44using RAMSPDToolkit . SPD ;
55using RAMSPDToolkit . SPD . Enums ;
@@ -13,19 +13,15 @@ internal class MemoryGroup : IGroup
1313{
1414 //Retry 12x
1515 private const int RetryCount = 12 ;
16-
1716 //Retry every 2.5 seconds
18- private const double RetryTime = 2500 ;
17+ private const int RetryTime = 2500 ;
1918 private static readonly object _lock = new ( ) ;
2019
2120 private readonly List < Hardware > _hardware = [ ] ;
22- private int _elapsedCounter ;
23-
24- private Timer _timer ;
2521
2622 static MemoryGroup ( )
2723 {
28- if ( Ring0 . IsOpen )
24+ if ( OperatingSystemHelper . IsAdministrator ( ) && Ring0 . IsOpen )
2925 {
3026 //Assign implementation of IDriver
3127 DriverManager . Driver = new RAMSPDToolkitDriver ( Ring0 . KernelDriver ) ;
@@ -38,30 +34,23 @@ public MemoryGroup(ISettings settings)
3834 _hardware . Add ( new TotalMemory ( settings ) ) ;
3935 _hardware . Add ( new VirtualMemory ( settings ) ) ;
4036
41- //No RAM detected
42- if ( ! DetectThermalSensors ( out List < SPDAccessor > accessors ) )
37+ if ( OperatingSystemHelper . IsAdministrator ( ) )
4338 {
44- //Retry a couple of times
45- //SMBus might not be detected right after boot
46- _timer = new Timer ( RetryTime ) ;
47-
48- _timer . Elapsed += ( _ , _ ) =>
39+ Task . Run ( async ( ) =>
4940 {
50- if ( _elapsedCounter ++ >= RetryCount || DetectThermalSensors ( out accessors ) )
41+ var _elapsedCounter = 0 ;
42+ while ( true )
5143 {
52- _timer . Stop ( ) ;
53- _timer = null ;
54-
55- if ( accessors != null )
56- AddDimms ( accessors , settings ) ;
44+ //SMBus might not be detected right after boot
45+ if ( DetectThermalSensors ( out var accessors ) || _elapsedCounter ++ >= RetryCount )
46+ {
47+ if ( accessors != null )
48+ AddDimms ( accessors , settings ) ;
49+ break ;
50+ }
51+ await Task . Delay ( RetryTime ) ;
5752 }
58- } ;
59-
60- _timer . Start ( ) ;
61- }
62- else
63- {
64- AddDimms ( accessors , settings ) ;
53+ } ) ;
6554 }
6655 }
6756
0 commit comments