Skip to content

Commit cc9b897

Browse files
authored
Fix possible collection was modified exception (#1836)
1 parent dfc5446 commit cc9b897

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

LibreHardwareMonitorLib/Hardware/Memory/MemoryGroup.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ private static bool DetectThermalSensors(out List<SPDAccessor> accessors)
176176

177177
private void AddDimms(List<SPDAccessor> accessors, ISettings settings)
178178
{
179+
List<Hardware> additions = [];
180+
179181
foreach (SPDAccessor ram in accessors)
180182
{
181183
//Default value
@@ -186,9 +188,11 @@ private void AddDimms(List<SPDAccessor> accessors, ISettings settings)
186188
name = $"{ram.GetModuleManufacturerString()} - {ram.ModulePartNumber()} (#{ram.Index})";
187189

188190
DimmMemory memory = new(ram, name, new Identifier($"memory/dimm/{ram.Index}"), settings);
189-
190-
_hardware.Add(memory);
191-
HardwareAdded?.Invoke(memory);
191+
additions.Add(memory);
192192
}
193+
194+
_hardware = [.. _hardware, .. additions];
195+
foreach (Hardware hardware in additions)
196+
HardwareAdded?.Invoke(hardware);
193197
}
194198
}

0 commit comments

Comments
 (0)