/// <summary>
 /// 指定したキーで待機します。
 /// </summary>
 /// <param name="key">待機するキー</param>
 public static void Wait(string key)
 {
     lock (LockObject)
     {
         if (!Semaphores.ContainsKey(key))
         {
             Semaphores.Add(key, new SemaphoreSlim(1, 1));
         }
     }
     Semaphores[key].Wait(3000);
 }
Beispiel #2
0
        /// <summary>
        /// Creates a new semaphore.
        /// </summary>
        /// <param name="id">The ID of the semaphore.</param>
        /// <param name="maximalCount">The maximal number of bots in the managed area.</param>
        /// <returns>The newly created semaphore.</returns>
        public QueueSemaphore CreateSemaphore(int id, int maximalCount)
        {
            QueueSemaphore semaphore = new QueueSemaphore(this, maximalCount)
            {
                ID = id
            };

            Semaphores.Add(semaphore);
            _idToSemaphore[semaphore.ID] = semaphore;
            return(semaphore);
        }
        /// <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();
        }