I have following code:
class Program
{
static AutoResetEvent objAuto = new AutoResetEvent(false);
static void Main(string[] args)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(SetState));
Console.ReadLine();
objAuto.Set();
}
static void SetState(object rsevent)
{
Console.WriteLine("Starting....");
bool result = objAuto.WaitOne(10000); // 10 seconds
Console.WriteLine("Finishing..." + result);
}
}
When I run this code and I hit Enter within 10 secs I get the value true in my result variable otherwise false.
What does this bool value indicates in each scenario…
I also need to know the meaning/use of another overload of WaitOne which has a boolean argument like following…
objAuto.WaitOne(10000,false)
The second parameter is exitContext what is this what kind of context does this exit ?
The return value indicates whether the event was signaled within the timeout you specified. If the return value is true, the event was signaled; if it is false, then the timeout expired.
The boolean argument for
exitContextindicates whether or not to release the synchronization context in which you invoke this method. See more on MSDN.