Skip to content

Free, open-source Windows optimization tool for performance, privacy, and simplicity.

refactor(threading): use System.Threading.Lock for the shared gates

fatDuck91a25ff49c10
diff --git a/optimizerDuck/Domain/UI/OptimizationState.cs b/optimizerDuck/Domain/UI/OptimizationState.cs
index 66e5f7b..bc1e611 100644
--- a/optimizerDuck/Domain/UI/OptimizationState.cs
+++ b/optimizerDuck/Domain/UI/OptimizationState.cs
@@ -1,4 +1,4 @@
-using System.Windows.Threading;
+using System.Windows.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using optimizerDuck.Resources.Languages;
using optimizerDuck.Services.Configuration;
@@ -12,7 +12,7 @@ public partial class OptimizationState : ObservableObject
{
private static DispatcherTimer? _globalTimer;
private static readonly List<WeakReference<OptimizationState>> _instances = [];
- private static readonly object _lock = new();
+ private static readonly Lock _lock = new();
private int _lastDisplayedSeconds = -1;
diff --git a/optimizerDuck/Services/System/RegistryWatcher.cs b/optimizerDuck/Services/System/RegistryWatcher.cs
index d042371..8a32364 100644
--- a/optimizerDuck/Services/System/RegistryWatcher.cs
+++ b/optimizerDuck/Services/System/RegistryWatcher.cs
@@ -1,4 +1,4 @@
-using System.Collections.Concurrent;
+using System.Collections.Concurrent;
using System.Runtime.InteropServices;
using Microsoft.Extensions.Logging;
@@ -93,7 +93,7 @@ internal sealed class RegistryWatcher(ILogger<RegistryWatcher> logger) : IRegist
private readonly string _path;
private readonly Action<string> _onChanged;
private readonly ILogger _logger;
- private readonly object _lock = new();
+ private readonly Lock _lock = new();
private IntPtr _hKey;
private AutoResetEvent? _event;
diff --git a/optimizerDuck/Services/System/SystemInfoService.cs b/optimizerDuck/Services/System/SystemInfoService.cs
index 9aa0f89..852d31c 100644
--- a/optimizerDuck/Services/System/SystemInfoService.cs
+++ b/optimizerDuck/Services/System/SystemInfoService.cs
@@ -1,4 +1,4 @@
-using System.Collections.Concurrent;
+using System.Collections.Concurrent;
using System.Globalization;
using System.IO;
using System.Management;
@@ -726,7 +726,7 @@ internal static class DiskProvider
// Physical topology changes ~never at runtime: cache successes, retry failures.
// The fast (2s-tick) path only reads these fields and never triggers a load.
- private static readonly object _cacheLock = new();
+ private static readonly Lock _cacheLock = new();
private static IReadOnlyList<PhysicalDiskInfo>? _cachedDisks;
private static IReadOnlyDictionary<string, PhysicalDiskInfo>? _cachedDriveMap;
private static readonly IReadOnlyDictionary<string, PhysicalDiskInfo> EmptyMap = new Dictionary<