Skip to content

Commit

Permalink
prevent crash on multithreaded access to MotherboardInfo.Manufacturer
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkirie committed Dec 7, 2023
1 parent 4e7f4e8 commit c40e205
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions HandheldCompanion/Managers/ControllerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,8 @@ private static async void XUsbDeviceArrived(PnPDetails details, DeviceEventArgs
Color _systemAccent = MainWindow.uiSettings.GetColorValue(UIColorType.Accent);
targetController.SetLightColor(_systemAccent.R, _systemAccent.G, _systemAccent.B);

var ManufacturerName = MotherboardInfo.Manufacturer.ToUpper();
switch(ManufacturerName)
string ManufacturerName = MotherboardInfo.Manufacturer.ToUpper();
switch (ManufacturerName)
{
case "AOKZOE":
case "ONE-NETBOOK TECHNOLOGY CO., LTD.":
Expand Down
17 changes: 15 additions & 2 deletions HandheldCompanion/Misc/MotherboardInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,25 @@ public static string InstallDate
}
}

private static string _Manufacturer;
public static string Manufacturer
{
get
{
if (!string.IsNullOrEmpty(_Manufacturer))
return _Manufacturer;

foreach (ManagementObject queryObj in baseboardCollection)
{
var query = queryObj["Manufacturer"];
if (query is not null)
return query.ToString();
{
_Manufacturer = query.ToString();
break;
}
}

return string.Empty;
return _Manufacturer;
}
}

Expand Down Expand Up @@ -132,8 +139,11 @@ public static int NumberOfCores
{
var query = queryObj["NumberOfCores"];
if (query is not null)
{
if (int.TryParse(query.ToString(), out var value))
_NumberOfCores = value;
break;
}
}

return _NumberOfCores;
Expand Down Expand Up @@ -245,8 +255,11 @@ public static uint ProcessorMaxClockSpeed
{
var query = queryObj["MaxClockSpeed"];
if (query is not null)
{
if (uint.TryParse(query.ToString(), out var value))
_ProcessorMaxClockSpeed = value;
break;
}
}

return _ProcessorMaxClockSpeed;
Expand Down

0 comments on commit c40e205

Please sign in to comment.