Exemplo n.º 1
0
 public void Post(SendOrPostCallback callback, object state)
 {
     lock (AsyncWorkQueue)
     {
         WorkRequest workRequest = new WorkRequest(callback, state, null);
         AsyncWorkQueue.Enqueue(workRequest);
     }
 }
Exemplo n.º 2
0
 public void Send(SendOrPostCallback callback, object state)
 {
     if (MainThreadID == Thread.CurrentThread.ManagedThreadId)
     {
         callback(state);
     }
     else
     {
         using (ManualResetEvent waitHandle = new ManualResetEvent(false))
         {
             lock (AsyncWorkQueue)
             {
                 WorkRequest workRequest = new WorkRequest(callback, state, waitHandle);
                 AsyncWorkQueue.Enqueue(workRequest);
             }
             waitHandle.WaitOne();
         }
     }
 }