Esempio n. 1
0
        public Mutex()
        {
            var code = MutexPrimitives.CreateMutex(out this.handle);

            if (code != ThreadResultCode.Success)
            {
                throw new Exception("Mutex creation failed with error code '" + code + "'.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Releases the mutex.
        /// </summary>
        public void ReleaseMutex()
        {
            var code = MutexPrimitives.UnlockMutex(handle);

            if (code != ThreadResultCode.Success)
            {
                throw new Exception("Mutex lock release failed with error code '" + code + "'.");
            }
        }
Esempio n. 3
0
        /// <inheritdoc/>
        public override bool WaitOne()
        {
            var code = MutexPrimitives.LockMutex(handle);

            if (code != ThreadResultCode.Success)
            {
                throw new Exception("Mutex lock acquisition failed with error code '" + code + "'.");
            }
            return(true);
        }
Esempio n. 4
0
        /// <inheritdoc/>
        protected override void Dispose(bool explicitDisposing)
        {
            var code = MutexPrimitives.DisposeMutex(handle);

            if (code != ThreadResultCode.Success)
            {
                if (explicitDisposing)
                {
                    throw new Exception("Mutex disposal failed with error code '" + code + "'.");
                }
            }
        }