3using System.Threading.Tasks;
 
   12        private readonly 
object synchObj = 
new object();
 
   29            : this(new Mutex(InitiallyOwned))
 
   39            : this(new Mutex(InitiallyOwned, Name))
 
   49        public AsyncMutex(
bool InitiallyOwned, 
string Name, out 
bool CreatedNew)
 
   50            : this(new Mutex(InitiallyOwned, Name, out CreatedNew))
 
   71            return new AsyncMutex(Mutex.OpenExisting(Name));
 
   82            if (!Mutex.TryOpenExisting(Name, out Mutex MutexObj))
 
   99                    if (this.executor is 
null)
 
  102                    return this.executor;
 
  113            this.executor = 
null;
 
  115            this.mutex?.Dispose();
 
  125            return this.Executor.Execute(this.WaitOneSync);
 
  128        private bool WaitOneSync()
 
  130            return this.mutex.WaitOne();
 
  138        public Task<bool> 
WaitOne(
int MillisecondsTimeout)
 
  140            return this.Executor.Execute(this.WaitOneSync, MillisecondsTimeout);
 
  143        private bool WaitOneSync(
int MillisecondsTimeout)
 
  145            return this.mutex.WaitOne(MillisecondsTimeout);
 
  155        public Task<bool> 
WaitOne(
int MillisecondsTimeout, 
bool ExitContext)
 
  157            return this.Executor.Execute(this.WaitOneSync, MillisecondsTimeout, ExitContext);
 
  160        private bool WaitOneSync(
int MillisecondsTimeout, 
bool ExitContext)
 
  162            return this.mutex.WaitOne(MillisecondsTimeout, ExitContext);
 
  172            return this.Executor.Execute<bool, TimeSpan>(this.WaitOneSync, Timeout);
 
  175        private bool WaitOneSync(TimeSpan Timeout)
 
  177            return this.mutex.WaitOne(Timeout);
 
  187        public Task<bool> 
WaitOne(TimeSpan Timeout, 
bool ExitContext)
 
  189            return this.Executor.Execute(this.WaitOneSync, Timeout, ExitContext);
 
  192        private bool WaitOneSync(TimeSpan Timeout, 
bool ExitContext)
 
  194            return this.mutex.WaitOne(Timeout, ExitContext);
 
  202            await this.Executor.Execute(this.ReleaseMutexSync);
 
  205        private bool ReleaseMutexSync()
 
  207            this.mutex.ReleaseMutex();
 
Asynchronous mutex class.
Task< bool > WaitOne(int MillisecondsTimeout, bool ExitContext)
Waits for the Mutex to be free, and locks it.
AsyncMutex(bool InitiallyOwned)
Asynchronous mutex class.
static bool TryOpenExisting(string Name, out AsyncMutex Result)
Tries to open an existing Mutex.
async Task ReleaseMutex()
Releases the mutex earlier aquired via a call to WaitOne.
Task< bool > WaitOne(TimeSpan Timeout)
Waits for the Mutex to be free, and locks it.
AsyncMutex(Mutex Mutex)
Asynchronous mutex class.
static AsyncMutex OpenExisting(string Name)
Opens an existing Mutex.
Task< bool > WaitOne(int MillisecondsTimeout)
Waits for the Mutex to be free, and locks it.
AsyncMutex(bool InitiallyOwned, string Name, out bool CreatedNew)
Asynchronous mutex class.
Task< bool > WaitOne(TimeSpan Timeout, bool ExitContext)
Waits for the Mutex to be free, and locks it.
void Dispose()
IDisposable.Dispose
AsyncMutex()
Asynchronous mutex class.
Task< bool > WaitOne()
Waits for the Mutex to be free, and locks it.
AsyncMutex(bool InitiallyOwned, string Name)
Asynchronous mutex class.
Class that executes tasks from the same the same thread, and that provides an asynchronous interface ...
void Dispose()
Disposes of the object and terminates the thread executor.