.Net Thread Synchronization

Posted by user209293 on Stack Overflow See other posts from Stack Overflow or by user209293
Published on 2010-03-08T07:30:23Z Indexed on 2010/03/08 7:36 UTC
Read the original article Hit count: 284

Filed under:
|

Hello,

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 prodcuer 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 funtion and producer calls set function, what would be state of Auto reset event object?

My requreiment is as soon as producer calls set method i have to downlaod fresh data from intenet . If doSomething function is running, when Producer calls set method, i have to interrupt it and call again.

Any help is appreciated. Regards Raju

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET