1- // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
1+ // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
22// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
33// Copyright (C) LibreHardwareMonitor and Contributors.
44// Partial Copyright (C) Michael Möller <mmoeller@openhardwaremonitor.org> and Contributors.
@@ -27,7 +27,7 @@ internal class MemoryGroup : IGroup, IHardwareChanged
2727
2828 private CancellationTokenSource _cancellationTokenSource ;
2929 private Exception _lastException ;
30- private bool _opened = false ;
30+ private bool _disposed = false ;
3131
3232 public MemoryGroup ( ISettings settings )
3333 {
@@ -50,8 +50,6 @@ public MemoryGroup(ISettings settings)
5050 {
5151 StartRetryTask ( settings ) ;
5252 }
53-
54- _opened = true ;
5553 }
5654
5755 public event HardwareEventHandler HardwareAdded ;
@@ -83,17 +81,17 @@ public string GetReport()
8381
8482 public void Close ( )
8583 {
84+ _cancellationTokenSource ? . Cancel ( ) ;
85+ _cancellationTokenSource ? . Dispose ( ) ;
86+ _cancellationTokenSource = null ;
87+
8688 lock ( _lock )
8789 {
88- _opened = false ;
8990 foreach ( Hardware ram in _hardware )
9091 ram . Close ( ) ;
9192
92- _hardware . Clear ( ) ;
93-
94- _cancellationTokenSource ? . Cancel ( ) ;
95- _cancellationTokenSource ? . Dispose ( ) ;
96- _cancellationTokenSource = null ;
93+ _hardware = [ ] ;
94+ _disposed = true ;
9795 }
9896 }
9997
@@ -103,9 +101,9 @@ private bool TryAddDimms(ISettings settings)
103101 {
104102 lock ( _lock )
105103 {
106- if ( ! _opened )
104+ if ( _disposed )
107105 {
108- return true ;
106+ return false ;
109107 }
110108
111109 if ( DetectThermalSensors ( out List < SPDAccessor > accessors ) )
@@ -138,24 +136,7 @@ private void StartRetryTask(ISettings settings)
138136
139137 if ( TryAddDimms ( settings ) )
140138 {
141- lock ( _lock )
142- {
143- if ( ! _opened )
144- {
145- return ;
146- }
147-
148- foreach ( Hardware hardware in _hardware . OfType < DimmMemory > ( ) )
149- {
150- HardwareAdded ? . Invoke ( hardware ) ;
151- }
152-
153- _cancellationTokenSource . Dispose ( ) ;
154- _cancellationTokenSource = null ;
155-
156- break ;
157- }
158-
139+ break ;
159140 }
160141 }
161142 } , _cancellationTokenSource . Token ) ;
@@ -195,8 +176,6 @@ private static bool DetectThermalSensors(out List<SPDAccessor> accessors)
195176
196177 private void AddDimms ( List < SPDAccessor > accessors , ISettings settings )
197178 {
198- List < Hardware > newHardwareList = [ .. _hardware ] ;
199-
200179 foreach ( SPDAccessor ram in accessors )
201180 {
202181 //Default value
@@ -207,9 +186,9 @@ private void AddDimms(List<SPDAccessor> accessors, ISettings settings)
207186 name = $ "{ ram . GetModuleManufacturerString ( ) } - { ram . ModulePartNumber ( ) } (#{ ram . Index } )";
208187
209188 DimmMemory memory = new ( ram , name , new Identifier ( $ "memory/dimm/{ ram . Index } ") , settings ) ;
210- newHardwareList . Add ( memory ) ;
211- }
212189
213- _hardware = newHardwareList ;
190+ _hardware . Add ( memory ) ;
191+ HardwareAdded ? . Invoke ( memory ) ;
192+ }
214193 }
215194}
0 commit comments