K
Ken Durden
The following code outputs the following:
True
True
Cannot access a disposed object (ObjectDisposedException)
Why does WaitAll differ in behavior from WaitOne?
Mutex mutex = new Mutex();
bool bLocked = mutex.WaitOne();
Console.WriteLine( "bLocked = {0}", bLocked );
IDisposable i = mutex;
i.Dispose();
bLocked = WaitHandle.WaitAll( new WaitHandle[]{ mutex } );
Console.WriteLine( "bLocked = {0}", bLocked );
bLocked = mutex.WaitOne();
Console.WriteLine( "bLocked = {0}", bLocked );
Also, the return value documentation for WaitHandle.WaitAll appears to
be wrong, it changes for each overload in bizarre ways.
Return Value
true when every element in waitHandles has received a signal. If the
current thread receives a request to abort before the signals are
received, this method returns false.
Return Value
true to exit the synchronization domain before the wait; otherwise,
false.
Return Value
true if the method exited the synchronization domain before the wait;
otherwise, false.
Ugh,
-ken
True
True
Cannot access a disposed object (ObjectDisposedException)
Why does WaitAll differ in behavior from WaitOne?
Mutex mutex = new Mutex();
bool bLocked = mutex.WaitOne();
Console.WriteLine( "bLocked = {0}", bLocked );
IDisposable i = mutex;
i.Dispose();
bLocked = WaitHandle.WaitAll( new WaitHandle[]{ mutex } );
Console.WriteLine( "bLocked = {0}", bLocked );
bLocked = mutex.WaitOne();
Console.WriteLine( "bLocked = {0}", bLocked );
Also, the return value documentation for WaitHandle.WaitAll appears to
be wrong, it changes for each overload in bizarre ways.
Return Value
true when every element in waitHandles has received a signal. If the
current thread receives a request to abort before the signals are
received, this method returns false.
Return Value
true to exit the synchronization domain before the wait; otherwise,
false.
Return Value
true if the method exited the synchronization domain before the wait;
otherwise, false.
Ugh,
-ken