Registering wait callbacks for events : ThreadPool : Thread C# Examples


C# Examples » Thread » ThreadPool »

 

Registering wait callbacks for events









    
using  System;
using  System.Collections.Generic;
using  System.Diagnostics;
using  System.IO;
using  System.Reflection;
using  System.Runtime;
using  System.Runtime.CompilerServices;
using  System.Security;
using  System.Text;

public  class  MainClass
{
        public  static  void  Main()
        {
                using  (EventWaitHandle  ewh  =  new  ManualResetEvent(false))
                using  (EventWaitHandle  callbackDoneEvent  =  new  ManualResetEvent(false))
                {
                        ThreadPool.RegisterWaitForSingleObject(ewh,
                                delegate  {
                                        Console.WriteLine("Callback  fired:  {0}",  Thread.CurrentThread.ManagedThreadId);
                                        callbackDoneEvent.Set();
                                },  null,  Timeout.Infinite,  true);

                        Console.WriteLine("Setting  the  event:  {0}",  Thread.CurrentThread.ManagedThreadId);
                        ewh.Set();

                        callbackDoneEvent.WaitOne();
                }
        }
}
    
   
  
   



Output

Setting the event: 1
Callback fired: 4


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Thread
» ThreadPool