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();
....
}