diff --git a/Lombiq.NodeJs.Extensions/CustomExecTasks/ExclusiveMutex.cs b/Lombiq.NodeJs.Extensions/CustomExecTasks/ExclusiveMutex.cs index 3c153719..0a3a28d1 100644 --- a/Lombiq.NodeJs.Extensions/CustomExecTasks/ExclusiveMutex.cs +++ b/Lombiq.NodeJs.Extensions/CustomExecTasks/ExclusiveMutex.cs @@ -6,9 +6,6 @@ namespace Lombiq.NodeJs.Extensions.CustomExecTasks; public class ExclusiveMutex(string mutexName, TimeSpan timeout) { - private readonly string _mutexName = mutexName; - private readonly TimeSpan _timeout = timeout; - public int RetryIntervalMs { get; set; } = 100; public int WaitTimeMs { get; set; } = 1000; @@ -17,9 +14,9 @@ public bool Execute( { var count = 1; var stopwatch = Stopwatch.StartNew(); - while (stopwatch.Elapsed <= _timeout) + while (stopwatch.Elapsed <= timeout) { - using (var mutex = new Mutex(initiallyOwned: false, _mutexName, out var createdNew)) + using (var mutex = new Mutex(initiallyOwned: false, mutexName, out var createdNew)) { // We only try to acquire the mutex in case it was freshly created, because that means that no other // processes are currently using it, including in a shared way. @@ -28,7 +25,7 @@ public bool Execute( try { logWait?.Invoke( - "Acquired exclusive access to {0} after {1}.", [_mutexName, stopwatch.Elapsed]); + "Acquired exclusive access to {0} after {1}.", [mutexName, stopwatch.Elapsed]); return functionToExecute(); } finally @@ -38,11 +35,11 @@ public bool Execute( } } - logWait?.Invoke("#{0} Waiting for exclusive access to {1}.", [count++, _mutexName]); + logWait?.Invoke("#{0} Waiting for exclusive access to {1}.", [count++, mutexName]); Thread.Sleep(RetryIntervalMs); } - logError?.Invoke("Failed to acquire exclusive access {0} in {1}.", [_mutexName, _timeout]); + logError?.Invoke("Failed to acquire exclusive access {0} in {1}.", [mutexName, timeout]); return false; } }