How-to dispose a waithandle correctly

Posted by TomTom on Stack Overflow See other posts from Stack Overflow or by TomTom
Published on 2010-04-27T14:37:29Z Indexed on 2010/04/27 14:43 UTC
Read the original article Hit count: 298

Filed under:
|

Hello,

I'm doing some multi-threading and use AutoResetEvents and ManualResetEvents do control my main - loop. When "destryoing" the threads I also have to dispose these signals, that's clear.

But I saw different ways how to dispose Waithandles, and I'm not sure which one is correct:

Version 1

if (disposing)
{
 this.threadExitEvent.SafeWaitHandle.Dispose();
 this.threadExitEvent.Close();
 this.threadExitEvent = null;
 ....
}

Version 2

if (disposing)
{
 this.threadExitEvent.Close();
 this.threadExitEvent = null;
 ....
}

Version 3

if (disposing)
{
 this.threadExitEvent.Close();
 ....
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about waithandle