ManualResetEvent - AutoResetEvent

  • Thread starter Thread starter Markus Freitag
  • Start date Start date
M

Markus Freitag

Guest
Hello,
what is the different between 'ManualResetEvent' and 'AutoResetEvent' ?
AutoResetEvent can be the Reset function?
I think makes no sense?
When do I initiate with 'true'?
public class AutoResetEventSample
{
private ManualResetEvent manualReset = new ManualResetEvent(false);

public void RunAll()
{
new Thread(Worker1).Start();
new Thread(Worker2).Start();
manualReset.Set();
Thread.Sleep(1000);
manualReset.Reset();
}

public class AutoResetEventSample
{
private AutoResetEvent autoReset = new AutoResetEvent(false);

public void RunAll()
{
new Thread(Worker1).Start();
new Thread(Worker2).Start();
autoReset.Set();
Thread.Sleep(1000);
autoReset.Set();
}
For my understanding.

AutoResetEvent only Set and WaitOne(1000) // wait 1000ms, then timeout exception
If I call Set, is automatically low Level, is a trigger-and-wait-maximum-time
1381758.jpg
ManualResetEvent Set, Reset and WaitOne(1000) // wait 1000ms, then time outexception
If I call Set, is 1 until I call Reset, is a signal edge that is 1 until reset.
1381759.jpg
Do I have to pay attention, if I have one thread, callback version or if I have multiple threads?

With best regards Markus

Continue reading...
 

Similar threads

Back
Top