Exemple #1
0
        /// <summary>
        /// Blocks the current thread until the condition is signaled.
        /// </summary>
        public void Await()
        {
            _waitingThreads.Add(ThreadHelper.CurrentThreadId);

            // Wait until signaled, at which time, we check to see if the signal
            // for the released thread matches this condition's id, and if so, the
            // thread is no longer in the waiting state
            string signal = null;

            while (signal != _signalId)
            {
                _monitor.Wait();

                signal = _threadSignals.Pop(ThreadHelper.CurrentThreadId);
            }

            // If we've made it this far, the current thread is no longer waiting
            _waitingThreads.Remove(ThreadHelper.CurrentThreadId);
        }