Whats is the difference between AutoResetEvent and Mutex
Different concept - a Mutex
is an exclusive token; only one person can have it; when they release it, somebody else can fight over it. An AutoResetEvent
is a gate that allows exactly one person through before closing, and which is operated by a button that is separate to the queue of people wanting to go through. When they pass through the gate immediately closes.
It depends.
In common, AutoResetEvent and Mutex can be replaced, AutoResetEvent.WaitOne = Mutex.WaitOne and AutoResetEvent.Set = Mutex.ReleaseMutex.
But they are different. You may mentioned that the Mutex has a "Release", which means you may "get" something while calling "WaitOne". The thing you may get is related to the thread which is calling.
You can call AutoResetEvent.Set in any thread. But you can only call Mutex.ReleaseMutex from the thread which is called Mutex.WaitOne and get the true as result.