Improve efficiency of asynclock
MODIFY
WalletWasabi/Nito/AsyncEx/AsyncMutex.cs
WalletWasabi/Nito/AsyncEx/AsyncMutex.cs
@@ -61,7 +61,13 @@ namespace Nito.AsyncEx
{
await AsyncLock.LockAsync(cancellationToken);
- Mutex = new Mutex(false, FullName);
+ Mutex = new Mutex(initiallyOwned: true, FullName, out bool createdNew);
+ if (createdNew)
+ {
+ return new Key(this);
+ }
+ else
+ {
// acquire the mutex (or timeout after 60 seconds)
// will return false if it timed out
var start = DateTime.Now;
@@ -75,6 +81,7 @@ namespace Nito.AsyncEx
}
await Task.Delay(pollInterval, cancellationToken);
}
+ }
// Let it go.
}
catch (TaskCanceledException)
@@ -102,6 +109,14 @@ namespace Nito.AsyncEx
private void ReleaseLock()
{
+ //Mutex?.ReleaseMutex();
+ try
+ {
+ Mutex?.ReleaseMutex();
+ }
+ catch (ApplicationException)
+ {
+ }
Mutex?.Dispose();
Mutex = null;
AsyncLock.ReleaseLock();

Improve efficiency of asynclock