Philip Rieck

Phil in .net

WaitHandles for the confused

I put up a somewhat old writeup on the ManualResetEvent and AutoResetEvent on my full blog, thought since it was .net, I'd post here as well.  Here's an excerpt:

Confused about WaitHandles? Sure you are. For one, they have the word "Event" on them.. Are they events? Do they call delegates?. For another, what's this "Reset" action, and why would I want to do it manually? And lastly, what does the documentation mean when it says "Signaled" and "Nonsignaled"? In project [codename] you see a good number of calls to WaitHandle-derived objects , both AutoReset and ManualReset. As the interaction can be somewhat complex, it can be difficult to decipher what is going on. Hopefully this simplified example will help clear things up.

You can find it here if you're interested.  It really was written for interns, but if you've never used them, you might find it useful.

Comments

Geora said:

Hi, I read your article "WaitHandles for the confused" which is very simplifies understanding of WaitHandles . I have a question regarding this issue.

I have a static member  m_event of type ManualResetEvent which is initialised to block.

After One of the threads calls WaitOne(30000,false)  on m_event and right afterwards ( less than 30 seconds) other thread calls Set()  on same m_event and exits the first thread does not procced till 30 seconds have past.

I there some fundamental issue that I don't understand

# May 29, 2007 5:53 AM

Ebert said:

Can I simply just say what a relief to find a person that truly

knows what they're discussing online. You certainly understand how to bring a problem to light and make it important. More people ought to check this out and understand this side of your story. I can't believe you aren't more popular because you surely have the gift.

# January 8, 2013 5:24 AM