I am planning to use Auto reset Event Handle for Inter Thread communication.
EventWaitHandle handle = new EventWaitHandle(false, EventResetMode.AutoReset);
My producer thread code look like below
produceSomething();
handle.Set();
In the consumer thread, I have to download data for every one minute or when producer
is called Set method
try
{
while(true)
{
handle.WaitOne(60000, false);
doSomething(); // Downloads data from Internet.
// Takes lot of time to complete it.
}
}
catch(ThreadAbortException)
{
cleanup();
}
My question is if consumer thread is running doSomething function and producer calls set function, what would be state of Auto reset event object?
My requirement is as soon as producer calls set method I have to download fresh data from the Internet. If doSomething function is running, when Producer calls set method, I have to interrupt it and call again.
An auto-reset event is like a gate that closes after the first thread goes through. If you set it while one or more threads are waiting then One thread wakes up, then the event is reset, the rest of the threads continue to wait.
If you set when no threads are waiting, then the first thread that calls
handle.WaitOnewill not wait, but it will cause the event to get reset and then continue on.from http://msdn.microsoft.com/en-us/library/system.threading.autoresetevent.aspx