2 using Microsoft.Win32.SafeHandles;
14 [__DynamicallyInvokable]
17 internal enum OpenExistingResult
26 [__DynamicallyInvokable]
29 private const int MAX_WAITHANDLES = 64;
36 internal bool hasThreadAffinity;
41 private const int WAIT_OBJECT_0 = 0;
43 private const int WAIT_ABANDONED = 128;
45 private const int WAIT_FAILED =
int.MaxValue;
47 private const int ERROR_TOO_MANY_POSTS = 298;
51 [Obsolete(
"Use the SafeWaitHandle property instead.")]
54 [SecuritySafeCritical]
57 if (safeWaitHandle !=
null)
59 return safeWaitHandle.DangerousGetHandle();
69 if (safeWaitHandle !=
null)
71 safeWaitHandle.SetHandleAsInvalid();
72 safeWaitHandle =
null;
88 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
92 if (safeWaitHandle ==
null)
96 return safeWaitHandle;
99 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.Success)]
111 safeWaitHandle =
null;
116 safeWaitHandle = value;
117 waitHandle = safeWaitHandle.DangerousGetHandle();
123 [SecuritySafeCritical]
124 private static IntPtr GetInvalidHandle()
126 return Win32Native.INVALID_HANDLE_VALUE;
130 [__DynamicallyInvokable]
136 [SecuritySafeCritical]
139 safeWaitHandle =
null;
141 hasThreadAffinity =
false;
147 safeWaitHandle = handle;
148 waitHandle = handle.DangerousGetHandle();
162 public virtual bool WaitOne(
int millisecondsTimeout,
bool exitContext)
164 if (millisecondsTimeout < -1)
168 return WaitOne((
long)millisecondsTimeout, exitContext);
187 if (-1 > num ||
int.MaxValue < num)
191 return WaitOne(num, exitContext);
200 [__DynamicallyInvokable]
203 return WaitOne(-1, exitContext:
false);
215 [__DynamicallyInvokable]
216 public virtual bool WaitOne(
int millisecondsTimeout)
218 return WaitOne(millisecondsTimeout, exitContext:
false);
231 [__DynamicallyInvokable]
234 return WaitOne(timeout, exitContext:
false);
237 [SecuritySafeCritical]
238 private bool WaitOne(
long timeout,
bool exitContext)
240 return InternalWaitOne(safeWaitHandle, timeout, hasThreadAffinity, exitContext);
244 internal static bool InternalWaitOne(
SafeHandle waitableSafeHandle,
long millisecondsTimeout,
bool hasThreadAffinity,
bool exitContext)
246 if (waitableSafeHandle ==
null)
250 int num = WaitOneNative(waitableSafeHandle, (uint)millisecondsTimeout, hasThreadAffinity, exitContext);
251 if (AppDomainPauseManager.IsPaused)
253 AppDomainPauseManager.ResumeEvent.WaitOneWithoutFAS();
257 ThrowAbandonedMutexException();
263 internal bool WaitOneWithoutFAS()
265 if (safeWaitHandle ==
null)
267 throw new ObjectDisposedException(
null, Environment.GetResourceString(
"ObjectDisposed_Generic"));
270 int num2 = WaitOneNative(safeWaitHandle, (uint)num, hasThreadAffinity, exitContext:
false);
273 ThrowAbandonedMutexException();
280 private static extern int WaitOneNative(
SafeHandle waitableSafeHandle, uint millisecondsTimeout,
bool hasThreadAffinity,
bool exitContext);
284 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
285 private static extern int WaitMultiple(
WaitHandle[] waitHandles,
int millisecondsTimeout,
bool exitContext,
bool WaitAll);
304 [SecuritySafeCritical]
307 if (waitHandles ==
null)
311 if (waitHandles.Length == 0)
315 if (waitHandles.Length > 64)
319 if (-1 > millisecondsTimeout)
324 for (
int i = 0; i < waitHandles.Length; i++)
327 if (waitHandle ==
null)
335 array[i] = waitHandle;
337 int num = WaitMultiple(array, millisecondsTimeout, exitContext,
WaitAll:
true);
338 if (AppDomainPauseManager.IsPaused)
340 AppDomainPauseManager.ResumeEvent.WaitOneWithoutFAS();
342 if (128 <= num && 128 + array.Length > num)
344 ThrowAbandonedMutexException();
372 if (-1 > num ||
int.MaxValue < num)
376 return WaitAll(waitHandles, (
int)num, exitContext);
392 [__DynamicallyInvokable]
395 return WaitAll(waitHandles, -1, exitContext:
true);
412 [__DynamicallyInvokable]
415 return WaitAll(waitHandles, millisecondsTimeout, exitContext:
true);
433 [__DynamicallyInvokable]
436 return WaitAll(waitHandles, timeout, exitContext:
true);
455 [SecuritySafeCritical]
456 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
459 if (waitHandles ==
null)
463 if (waitHandles.Length == 0)
467 if (64 < waitHandles.Length)
471 if (-1 > millisecondsTimeout)
476 for (
int i = 0; i < waitHandles.Length; i++)
479 if (waitHandle ==
null)
487 array[i] = waitHandle;
489 int num = WaitMultiple(array, millisecondsTimeout, exitContext,
WaitAll:
false);
490 if (AppDomainPauseManager.IsPaused)
492 AppDomainPauseManager.ResumeEvent.WaitOneWithoutFAS();
494 if (128 <= num && 128 + array.Length > num)
496 int num2 = num - 128;
497 if (0 <= num2 && num2 < array.Length)
499 ThrowAbandonedMutexException(num2, array[num2]);
503 ThrowAbandonedMutexException();
528 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
532 if (-1 > num ||
int.MaxValue < num)
536 return WaitAny(waitHandles, (
int)num, exitContext);
552 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
553 [__DynamicallyInvokable]
556 return WaitAny(waitHandles, timeout, exitContext:
true);
570 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
571 [__DynamicallyInvokable]
574 return WaitAny(waitHandles, -1, exitContext:
true);
589 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
590 [__DynamicallyInvokable]
593 return WaitAny(waitHandles, millisecondsTimeout, exitContext:
true);
598 private static extern int SignalAndWaitOne(
SafeWaitHandle waitHandleToSignal,
SafeWaitHandle waitHandleToWaitOn,
int millisecondsTimeout,
bool hasThreadAffinity,
bool exitContext);
615 return SignalAndWait(toSignal, toWaitOn, -1, exitContext:
false);
641 if (-1 > num ||
int.MaxValue < num)
645 return SignalAndWait(toSignal, toWaitOn, (
int)num, exitContext);
667 [SecuritySafeCritical]
670 if (toSignal ==
null)
674 if (toWaitOn ==
null)
678 if (-1 > millisecondsTimeout)
682 int num = SignalAndWaitOne(toSignal.safeWaitHandle, toWaitOn.safeWaitHandle, millisecondsTimeout, toWaitOn.hasThreadAffinity, exitContext);
683 if (
int.MaxValue != num && toSignal.hasThreadAffinity)
690 ThrowAbandonedMutexException();
703 private static void ThrowAbandonedMutexException()
708 private static void ThrowAbandonedMutexException(
int location,
WaitHandle handle)
710 throw new AbandonedMutexException(location, handle);
716 Dispose(explicitDisposing:
true);
723 [SecuritySafeCritical]
724 [__DynamicallyInvokable]
725 protected virtual void Dispose(
bool explicitDisposing)
727 if (safeWaitHandle !=
null)
729 safeWaitHandle.Close();
734 [__DynamicallyInvokable]
737 Dispose(explicitDisposing:
true);
void Dispose()
Releases all resources used by the current instance of the T:System.Threading.WaitHandle class.
virtual bool WaitOne(TimeSpan timeout, bool exitContext)
Blocks the current thread until the current instance receives a signal, using a T:System....
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout)
Waits for all the elements in the specified array to receive a signal, using an T:System....
static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext)
Waits for any of the elements in the specified array to receive a signal, using a 32-bit signed integ...
static bool SignalAndWait(WaitHandle toSignal, WaitHandle toWaitOn, TimeSpan timeout, bool exitContext)
Signals one T:System.Threading.WaitHandle and waits on another, specifying the time-out interval as a...
Encapsulates operating system–specific objects that wait for exclusive access to shared resources.
SafeWaitHandle SafeWaitHandle
Gets or sets the native operating system handle.
static void SuppressFinalize(object obj)
Requests that the common language runtime not call the finalizer for the specified object.
static bool SignalAndWait(WaitHandle toSignal, WaitHandle toWaitOn, int millisecondsTimeout, bool exitContext)
Signals one T:System.Threading.WaitHandle and waits on another, specifying a time-out interval as a 3...
static bool WaitAll(WaitHandle[] waitHandles)
Waits for all the elements in the specified array to receive a signal.
static bool WaitAll(WaitHandle[] waitHandles, TimeSpan timeout, bool exitContext)
Waits for all the elements in the specified array to receive a signal, using a T:System....
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
static bool WaitAll(WaitHandle[] waitHandles, TimeSpan timeout)
Waits for all the elements in the specified array to receive a signal, using a T:System....
The exception that is thrown when the value of an argument is outside the allowable range of values a...
static void KeepAlive(object obj)
References the specified object, which makes it ineligible for garbage collection from the start of t...
static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout)
Waits for any of the elements in the specified array to receive a signal, using a 32-bit signed integ...
virtual IntPtr Handle
Gets or sets the native operating system handle.
double TotalMilliseconds
Gets the value of the current T:System.TimeSpan structure expressed in whole and fractional milliseco...
virtual bool WaitOne(int millisecondsTimeout, bool exitContext)
Blocks the current thread until the current T:System.Threading.WaitHandle receives a signal,...
Represents a wrapper class for operating system handles. This class must be inherited.
Cer
Specifies a method's behavior when called within a constrained execution region.
The exception that is thrown when an operation is performed on a disposed object.
virtual bool WaitOne(int millisecondsTimeout)
Blocks the current thread until the current T:System.Threading.WaitHandle receives a signal,...
SecurityAction
Specifies the security actions that can be performed using declarative security.
static int WaitAny(WaitHandle[] waitHandles, TimeSpan timeout, bool exitContext)
Waits for any of the elements in the specified array to receive a signal, using a T:System....
Provides information about, and means to manipulate, the current environment and platform....
static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext)
Waits for all the elements in the specified array to receive a signal, using an T:System....
static bool SignalAndWait(WaitHandle toSignal, WaitHandle toWaitOn)
Signals one T:System.Threading.WaitHandle and waits on another.
static readonly IntPtr InvalidHandle
Represents an invalid native operating system handle. This field is read-only.
virtual void Dispose(bool explicitDisposing)
When overridden in a derived class, releases the unmanaged resources used by the T:System....
A platform-specific type that is used to represent a pointer or a handle.
static int WaitAny(WaitHandle[] waitHandles)
Waits for any of the elements in the specified array to receive a signal.
static void PrepareConstrainedRegions()
Designates a body of code as a constrained execution region (CER).
The exception that is thrown when one thread acquires a T:System.Threading.Mutex object that another ...
MethodImplOptions
Defines the details of how a method is implemented.
static void EndCriticalRegion()
Notifies a host that execution is about to enter a region of code in which the effects of a thread ab...
virtual void Close()
Releases all resources held by the current T:System.Threading.WaitHandle.
static int WaitAny(WaitHandle[] waitHandles, TimeSpan timeout)
Waits for any of the elements in the specified array to receive a signal, using a T:System....
Controls the system garbage collector, a service that automatically reclaims unused memory.
static bool IsTransparentProxy(object proxy)
Returns a Boolean value that indicates whether the given object is a transparent proxy or a real obje...
virtual bool WaitOne(TimeSpan timeout)
Blocks the current thread until the current instance receives a signal, using a T:System....
virtual bool WaitOne()
Blocks the current thread until the current T:System.Threading.WaitHandle receives a signal.
The exception that is thrown when one of the arguments provided to a method is not valid.
WaitHandle()
Initializes a new instance of the T:System.Threading.WaitHandle class.
Represents a time interval.To browse the .NET Framework source code for this type,...
static void EndThreadAffinity()
Notifies a host that managed code has finished executing instructions that depend on the identity of ...
The exception that is thrown when a method call is invalid for the object's current state.
Consistency
Specifies a reliability contract.
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
SecurityPermissionFlag
Specifies access flags for the security permission object.
Provides several methods for using and publishing remoted objects and proxies. This class cannot be i...
const int WaitTimeout
Indicates that a M:System.Threading.WaitHandle.WaitAny(System.Threading.WaitHandle[],...
Provides a set of static methods and properties that provide support for compilers....
Enables access to objects across application domain boundaries in applications that support remoting.
Creates and controls a thread, sets its priority, and gets its status.