From f7697fe46dc74ccd973fb707ed790f24126ae802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 14:07:59 +0100 Subject: [PATCH] Removing fields. --- .../CustomExecTasks/SharedMutex.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Lombiq.NodeJs.Extensions/CustomExecTasks/SharedMutex.cs b/Lombiq.NodeJs.Extensions/CustomExecTasks/SharedMutex.cs index fa9aacc3..cf44c6b6 100644 --- a/Lombiq.NodeJs.Extensions/CustomExecTasks/SharedMutex.cs +++ b/Lombiq.NodeJs.Extensions/CustomExecTasks/SharedMutex.cs @@ -6,9 +6,6 @@ namespace Lombiq.NodeJs.Extensions.CustomExecTasks; public class SharedMutex(string mutexName, TimeSpan timeout) { - private readonly string _mutexName = mutexName; - private readonly TimeSpan _timeout = timeout; - public int RetryIntervalMs { get; set; } = 100; public bool Execute( @@ -16,9 +13,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)) + using (var mutex = new Mutex(initiallyOwned: false, mutexName)) { if (mutex.WaitOne(0)) { @@ -26,18 +23,18 @@ public bool Execute( // it is currently not "locked", i.e. in exclusive usage. mutex.ReleaseMutex(); - logWait?.Invoke("Acquired shared access to {0} in {1}.", [_mutexName, stopwatch.Elapsed]); + logWait?.Invoke("Acquired shared access to {0} in {1}.", [mutexName, stopwatch.Elapsed]); return functionToExecute(); } } - logWait?.Invoke("#{0} Waiting for shared access to {1}.", [count++, _mutexName]); + logWait?.Invoke("#{0} Waiting for shared access to {1}.", [count++, mutexName]); Thread.Sleep(RetryIntervalMs); } - logError?.Invoke("Failed to acquire {0} in {1}.", [_mutexName, _timeout]); + logError?.Invoke("Failed to acquire {0} in {1}.", [mutexName, timeout]); return false; } }