示例#1
0
        void WorkerThreadProc()
        {
            while (true)
            {
                if (WaitHandle.WaitAny(new WaitHandle[] { workReady, terminate }) == 1)
                {
                    return;
                }

                Tuple <SendOrPostCallback, object, object> work;
                while (workQueue.TryDequeue(out work))
                {
                    // Set workReady() to wake up other threads, since there might still be work on the queue (fixes #877)
                    workReady.Set();
                    if (work.Item3 == null)    // Fix for #461, so we don't try to run on a null execution context
                    {
                        RunOnSyncContext(work.Item1, work.Item2);
                    }
                    else
                    {
                        ExecutionContextHelper.Run(work.Item3, _ => RunOnSyncContext(work.Item1, work.Item2));
                    }
                }
            }
        }
 /// <inheritdoc/>
 public override void Post(SendOrPostCallback d, object state)
 {
     // HACK: DNX on Unix seems to be calling this after it's disposed. In that case,
     // we'll just execute the code directly, which is a violation of the contract
     // but should be safe in this situation.
     if (disposed)
     {
         Send(d, state);
     }
     else
     {
         var context = ExecutionContextHelper.Capture();
         workQueue.Enqueue(Tuple.Create(d, state, context));
         workReady.Set();
     }
 }
        void WorkerThreadProc()
        {
            while (true)
            {
                if (WaitHandle.WaitAny(new WaitHandle[] { workReady, terminate }) == 1)
                {
                    return;
                }

                Tuple <SendOrPostCallback, object, object> work;
                while (workQueue.TryDequeue(out work))
                {
                    if (work.Item3 == null)    // Fix for #461, so we don't try to run on a null execution context
                    {
                        RunOnSyncContext(work.Item1, work.Item2);
                    }
                    else
                    {
                        ExecutionContextHelper.Run(work.Item3, _ => RunOnSyncContext(work.Item1, work.Item2));
                    }
                }
            }
        }