Exemple #1
0
        public async Task LockAsync()
        {
            await LockSemaphore.WaitAsync().ConfigureAwait(false);

            TimeoutCancelSource = new CancellationTokenSource();
            UnlockTask          = Task.Delay(TimeSpan.FromSeconds(30), TimeoutCancel);
            _ = UnlockTask.ContinueWith(InternalUnlock, TaskContinuationOptions.NotOnCanceled);
        }
        /// <summary>
        /// 指定したキーで待機します。
        /// </summary>
        /// <param name="key">待機するキー</param>
        public static async Task WaitAsync(string key)
        {
            await LockSemaphore.WaitAsync();

            try
            {
                if (!Semaphores.ContainsKey(key))
                {
                    Semaphores.Add(key, new SemaphoreSlim(1, 1));
                }
            }
            finally
            {
                LockSemaphore.Release();
            }
            await Semaphores[key].WaitAsync();
        }
Exemple #3
0
 public Task WaitAsync()
 => LockSemaphore.WaitAsync();