@@ -21,7 +21,7 @@ internal class MemoryGroup : IGroup, IHardwareChanged
2121
2222 private CancellationTokenSource _cancellationTokenSource ;
2323 private Exception _lastException ;
24- private bool _opened = false ;
24+ private bool _disposed = false ;
2525
2626 public MemoryGroup ( ISettings settings )
2727 {
@@ -44,8 +44,6 @@ public MemoryGroup(ISettings settings)
4444 {
4545 StartRetryTask ( settings ) ;
4646 }
47-
48- _opened = true ;
4947 }
5048
5149 public event HardwareEventHandler HardwareAdded ;
@@ -77,17 +75,17 @@ public string GetReport()
7775
7876 public void Close ( )
7977 {
78+ _cancellationTokenSource ? . Cancel ( ) ;
79+ _cancellationTokenSource ? . Dispose ( ) ;
80+ _cancellationTokenSource = null ;
81+
8082 lock ( _lock )
8183 {
82- _opened = false ;
8384 foreach ( Hardware ram in _hardware )
8485 ram . Close ( ) ;
8586
86- _hardware . Clear ( ) ;
87-
88- _cancellationTokenSource ? . Cancel ( ) ;
89- _cancellationTokenSource ? . Dispose ( ) ;
90- _cancellationTokenSource = null ;
87+ _hardware = [ ] ;
88+ _disposed = true ;
9189 }
9290 }
9391
@@ -97,9 +95,9 @@ private bool TryAddDimms(ISettings settings)
9795 {
9896 lock ( _lock )
9997 {
100- if ( ! _opened )
98+ if ( _disposed )
10199 {
102- return true ;
100+ return false ;
103101 }
104102
105103 if ( DetectThermalSensors ( out List < SPDAccessor > accessors ) )
@@ -132,24 +130,7 @@ private void StartRetryTask(ISettings settings)
132130
133131 if ( TryAddDimms ( settings ) )
134132 {
135- lock ( _lock )
136- {
137- if ( ! _opened )
138- {
139- return ;
140- }
141-
142- foreach ( Hardware hardware in _hardware . OfType < DimmMemory > ( ) )
143- {
144- HardwareAdded ? . Invoke ( hardware ) ;
145- }
146-
147- _cancellationTokenSource . Dispose ( ) ;
148- _cancellationTokenSource = null ;
149-
150- break ;
151- }
152-
133+ break ;
153134 }
154135 }
155136 } , _cancellationTokenSource . Token ) ;
@@ -189,8 +170,6 @@ private static bool DetectThermalSensors(out List<SPDAccessor> accessors)
189170
190171 private void AddDimms ( List < SPDAccessor > accessors , ISettings settings )
191172 {
192- List < Hardware > newHardwareList = [ .. _hardware ] ;
193-
194173 foreach ( SPDAccessor ram in accessors )
195174 {
196175 //Default value
@@ -201,9 +180,9 @@ private void AddDimms(List<SPDAccessor> accessors, ISettings settings)
201180 name = $ "{ ram . GetModuleManufacturerString ( ) } - { ram . ModulePartNumber ( ) } (#{ ram . Index } )";
202181
203182 DimmMemory memory = new ( ram , name , new Identifier ( $ "memory/dimm/{ ram . Index } ") , settings ) ;
204- newHardwareList . Add ( memory ) ;
205- }
206183
207- _hardware = newHardwareList ;
184+ _hardware . Add ( memory ) ;
185+ HardwareAdded ? . Invoke ( memory ) ;
186+ }
208187 }
209188}
0 commit comments