public static int WaitAny(WaitHandle[] waitHandles, TimeSpan timeout, bool exitContext) { CheckArray(waitHandles, false); long ms = (long)timeout.TotalMilliseconds; if (ms < -1 || ms > Int32.MaxValue) { throw new ArgumentOutOfRangeException("timeout"); } try { if (exitContext) { SynchronizationAttribute.ExitContext(); } return(WaitAny_internal(waitHandles, (int)ms, exitContext)); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } } }
static bool ObjWait(bool exitContext, int millisecondsTimeout, Object obj) { if (millisecondsTimeout < 0 && millisecondsTimeout != (int)Timeout.Infinite) { throw new ArgumentOutOfRangeException("millisecondsTimeout"); } if (!Monitor_test_synchronised(obj)) { throw new SynchronizationLockException("Object is not synchronized"); } try { #if !DISABLE_REMOTING if (exitContext) { SynchronizationAttribute.ExitContext(); } #endif return(Monitor_wait(obj, millisecondsTimeout)); } finally { #if !DISABLE_REMOTING if (exitContext) { SynchronizationAttribute.EnterContext(); } #endif } }
static int WaitOneNative(SafeHandle waitableSafeHandle, uint millisecondsTimeout, bool hasThreadAffinity, bool exitContext) { bool release = false; try { #if !DISABLE_REMOTING if (exitContext) { SynchronizationAttribute.ExitContext(); } #endif waitableSafeHandle.DangerousAddRef(ref release); return(WaitOne_internal(waitableSafeHandle.DangerousGetHandle(), (int)millisecondsTimeout)); } finally { if (release) { waitableSafeHandle.DangerousRelease(); } #if !DISABLE_REMOTING if (exitContext) { SynchronizationAttribute.EnterContext(); } #endif } }
public static bool WaitAll(WaitHandle[] waitHandles, TimeSpan timeout, bool exitContext) { CheckArray(waitHandles, true); long ms = (long)timeout.TotalMilliseconds; if (ms < -1 || ms > Int32.MaxValue) { throw new ArgumentOutOfRangeException("timeout"); } try { if (exitContext) { #if MONOTOUCH throw new NotSupportedException("exitContext == true is not supported"); #else SynchronizationAttribute.ExitContext(); #endif } return(WaitAll_internal(waitHandles, (int)ms, exitContext)); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } } }
public static int WaitAny(WaitHandle[] waitHandles, TimeSpan timeout, bool exitContext) { WaitHandle.CheckArray(waitHandles, false); long num = (long)timeout.TotalMilliseconds; if (num < -1L || num > 2147483647L) { throw new ArgumentOutOfRangeException("timeout"); } int result; try { if (exitContext) { SynchronizationAttribute.ExitContext(); } result = WaitHandle.WaitAny_internal(waitHandles, (int)num, exitContext); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } } return(result); }
public static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) { CheckArray(waitHandles, false); // check negative - except for -1 (which is Timeout.Infinite) if (millisecondsTimeout < Timeout.Infinite) { throw new ArgumentOutOfRangeException("millisecondsTimeout"); } try { if (exitContext) { SynchronizationAttribute.ExitContext(); } return(WaitAny_internal(waitHandles, millisecondsTimeout, exitContext)); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } } }
public void Constructor_Default() { SynchronizationAttribute sa = new SynchronizationAttribute(); Assert.IsFalse(sa.IsReEntrant, "IsReEntrant"); Assert.IsFalse(sa.Locked, "Locked"); }
public static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) { CheckArray(waitHandles, true); // check negative - except for -1 (which is Timeout.Infinite) if (millisecondsTimeout < Timeout.Infinite) { throw new ArgumentOutOfRangeException("millisecondsTimeout"); } try { if (exitContext) { #if MONOTOUCH throw new NotSupportedException("exitContext == true is not supported"); #else SynchronizationAttribute.ExitContext(); #endif } return(WaitAll_internal(waitHandles, millisecondsTimeout, false)); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } } }
static int WaitOneNative(SafeHandle waitableSafeHandle, uint millisecondsTimeout, bool hasThreadAffinity, bool exitContext) { #if MONOTOUCH if (exitContext) { throw new NotSupportedException("exitContext == true is not supported"); } #endif bool release = false; try { if (exitContext) { SynchronizationAttribute.ExitContext(); } waitableSafeHandle.DangerousAddRef(ref release); return(WaitOne_internal(waitableSafeHandle.DangerousGetHandle(), (int)millisecondsTimeout, exitContext)); } finally { if (release) { waitableSafeHandle.DangerousRelease(); } if (exitContext) { SynchronizationAttribute.EnterContext(); } } }
public void Constructor_IntBool() { SynchronizationAttribute sa = new SynchronizationAttribute(SynchronizationAttribute.NOT_SUPPORTED, true); Assert.IsTrue(sa.IsReEntrant, "IsReEntrant"); Assert.IsFalse(sa.Locked, "Locked"); }
/// <summary>Waits for all the elements in the specified array to receive a signal, using an <see cref="T:System.Int32" /> value to specify the time interval and specifying whether to exit the synchronization domain before the wait.</summary> /// <returns>true when every element in <paramref name="waitHandles" /> has received a signal; otherwise, false.</returns> /// <param name="waitHandles">A WaitHandle array containing the objects for which the current instance will wait. This array cannot contain multiple references to the same object (duplicates). </param> /// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see cref="F:System.Threading.Timeout.Infinite" /> (-1) to wait indefinitely. </param> /// <param name="exitContext">true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it afterward; otherwise, false. </param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="waitHandles" /> parameter is null.-or- One or more of the objects in the <paramref name="waitHandles" /> array is null. -or-<paramref name="waitHandles" /> is an array with no elements and the .NET Framework version is 2.0 or later. </exception> /// <exception cref="T:System.DuplicateWaitObjectException">The <paramref name="waitHandles" /> array contains elements that are duplicates. </exception> /// <exception cref="T:System.NotSupportedException">The number of objects in <paramref name="waitHandles" /> is greater than the system permits.-or- The <see cref="T:System.STAThreadAttribute" /> attribute is applied to the thread procedure for the current thread, and <paramref name="waitHandles" /> contains more than one element. </exception> /// <exception cref="T:System.ApplicationException"> /// <paramref name="waitHandles" /> is an array with no elements and the .NET Framework version is 1.0 or 1.1. </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="millisecondsTimeout" /> is a negative number other than -1, which represents an infinite time-out. </exception> /// <exception cref="T:System.Threading.AbandonedMutexException">The wait completed because a thread exited without releasing a mutex. This exception is not thrown on Windows 98 or Windows Millennium Edition.</exception> /// <exception cref="T:System.InvalidOperationException">The <paramref name="waitHandles" /> array contains a transparent proxy for a <see cref="T:System.Threading.WaitHandle" /> in another application domain.</exception> /// <filterpriority>1</filterpriority> public static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) { WaitHandle.CheckArray(waitHandles, true); if (millisecondsTimeout < -1) { throw new ArgumentOutOfRangeException("millisecondsTimeout"); } bool result; try { if (exitContext) { SynchronizationAttribute.ExitContext(); } result = WaitHandle.WaitAll_internal(waitHandles, millisecondsTimeout, false); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } } return(result); }
/// <summary>Blocks the current thread until the current instance receives a signal, using a <see cref="T:System.TimeSpan" /> to specify the time interval and specifying whether to exit the synchronization domain before the wait.</summary> /// <returns>true if the current instance receives a signal; otherwise, false.</returns> /// <param name="timeout">A <see cref="T:System.TimeSpan" /> that represents the number of milliseconds to wait, or a <see cref="T:System.TimeSpan" /> that represents -1 milliseconds to wait indefinitely. </param> /// <param name="exitContext">true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it afterward; otherwise, false. </param> /// <exception cref="T:System.ObjectDisposedException">The current instance has already been disposed. </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="timeout" /> is a negative number other than -1 milliseconds, which represents an infinite time-out.-or-<paramref name="timeout" /> is greater than <see cref="F:System.Int32.MaxValue" />. </exception> /// <exception cref="T:System.Threading.AbandonedMutexException">The wait completed because a thread exited without releasing a mutex. This exception is not thrown on Windows 98 or Windows Millennium Edition.</exception> /// <exception cref="T:System.InvalidOperationException">The current instance is a transparent proxy for a <see cref="T:System.Threading.WaitHandle" /> in another application domain.</exception> /// <filterpriority>2</filterpriority> public virtual bool WaitOne(TimeSpan timeout, bool exitContext) { this.CheckDisposed(); long num = (long)timeout.TotalMilliseconds; if (num < -1L || num > 2147483647L) { throw new ArgumentOutOfRangeException("timeout"); } bool flag = false; bool result; try { if (exitContext) { SynchronizationAttribute.ExitContext(); } this.safe_wait_handle.DangerousAddRef(ref flag); result = this.WaitOne_internal(this.safe_wait_handle.DangerousGetHandle(), (int)num, exitContext); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } if (flag) { this.safe_wait_handle.DangerousRelease(); } } return(result); }
/// <summary>Blocks the current thread until the current wait handle receives a signal, using a 32-bit signed integer to specify the time interval and specifying whether to exit the synchronization domain before the wait.</summary> /// <returns>true if the current instance receives a signal; otherwise, false.</returns> /// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see cref="F:System.Threading.Timeout.Infinite" /> (-1) to wait indefinitely. </param> /// <param name="exitContext">true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it afterward; otherwise, false. </param> /// <exception cref="T:System.ObjectDisposedException">The current instance has already been disposed. </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="millisecondsTimeout" /> is a negative number other than -1, which represents an infinite time-out. </exception> /// <exception cref="T:System.Threading.AbandonedMutexException">The wait completed because a thread exited without releasing a mutex. This exception is not thrown on Windows 98 or Windows Millennium Edition.</exception> /// <exception cref="T:System.InvalidOperationException">The current instance is a transparent proxy for a <see cref="T:System.Threading.WaitHandle" /> in another application domain.</exception> /// <filterpriority>2</filterpriority> public virtual bool WaitOne(int millisecondsTimeout, bool exitContext) { this.CheckDisposed(); if (millisecondsTimeout < -1) { throw new ArgumentOutOfRangeException("millisecondsTimeout"); } bool flag = false; bool result; try { if (exitContext) { SynchronizationAttribute.ExitContext(); } this.safe_wait_handle.DangerousAddRef(ref flag); result = this.WaitOne_internal(this.safe_wait_handle.DangerousGetHandle(), millisecondsTimeout, exitContext); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } if (flag) { this.safe_wait_handle.DangerousRelease(); } } return(result); }
public virtual bool WaitOne(TimeSpan timeout, bool exitContext) { CheckDisposed(); long ms = (long)timeout.TotalMilliseconds; if (ms < -1 || ms > Int32.MaxValue) { throw new ArgumentOutOfRangeException("timeout"); } bool release = false; try { if (exitContext) { SynchronizationAttribute.ExitContext(); } safe_wait_handle.DangerousAddRef(ref release); return(WaitOne_internal(safe_wait_handle.DangerousGetHandle(), (int)ms, exitContext)); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } if (release) { safe_wait_handle.DangerousRelease(); } } }
public virtual bool WaitOne(int millisecondsTimeout, bool exitContext) { CheckDisposed(); // check negative - except for -1 (which is Timeout.Infinite) if (millisecondsTimeout < Timeout.Infinite) { throw new ArgumentOutOfRangeException("millisecondsTimeout"); } bool release = false; try { if (exitContext) { SynchronizationAttribute.ExitContext(); } safe_wait_handle.DangerousAddRef(ref release); return(WaitOne_internal(safe_wait_handle.DangerousGetHandle(), millisecondsTimeout, exitContext)); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } if (release) { safe_wait_handle.DangerousRelease(); } } }
// We rely on the reference source implementation of WaitHandle, and it delegates to a function named // WaitOneNative to perform the actual operation of waiting on a handle. // This native operation actually has to call back into managed code and invoke .Wait // on the current SynchronizationContext. As such, our implementation of this "native" method // is actually managed code, and the real native icall being used is Wait_internal. static int WaitOneNative(SafeHandle waitableSafeHandle, uint millisecondsTimeout, bool hasThreadAffinity, bool exitContext) { bool release = false; #if !MONODROID var context = SynchronizationContext.Current; #endif try { waitableSafeHandle.DangerousAddRef(ref release); #if !DISABLE_REMOTING if (exitContext) { SynchronizationAttribute.ExitContext(); } #endif #if !MONODROID // HACK: Documentation (and public posts by experts like Joe Duffy) suggests that // users must first call SetWaitNotificationRequired to flag that a given synchronization // context overrides .Wait. Because invoking the Wait method is somewhat expensive, we use // the notification-required flag to determine whether or not we should invoke the managed // wait method. // Another option would be to check whether this context uses the default Wait implementation, // but I don't know of a cheap way to do this that handles derived types correctly. // If the thread does not have a synchronization context set at all, we can safely just // jump directly to invoking Wait_internal. if ((context != null) && context.IsWaitNotificationRequired()) { return(context.Wait( new IntPtr[] { waitableSafeHandle.DangerousGetHandle() }, false, (int)millisecondsTimeout )); } else #endif { unsafe { IntPtr handle = waitableSafeHandle.DangerousGetHandle(); return(Wait_internal(&handle, 1, false, (int)millisecondsTimeout)); } } } finally { if (release) { waitableSafeHandle.DangerousRelease(); } #if !DISABLE_REMOTING if (exitContext) { SynchronizationAttribute.EnterContext(); } #endif } }
public void DeserializeKnownValue() { MemoryStream ms = new MemoryStream(serialized_sync_attr); BinaryFormatter bf = new BinaryFormatter(); SynchronizationAttribute sa = (SynchronizationAttribute)bf.Deserialize(ms); Assert.IsTrue(sa.IsReEntrant, "IsReEntrant"); Assert.IsFalse(sa.Locked, "Locked"); }
static int WaitMultiple(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext, bool WaitAll) { if (waitHandles.Length > MaxWaitHandles) return WAIT_FAILED; int release_last = -1; var context = SynchronizationContext.Current; try { #if !DISABLE_REMOTING if (exitContext) SynchronizationAttribute.ExitContext (); #endif for (int i = 0; i < waitHandles.Length; ++i) { try {} finally { /* we have to put it in a finally block, to avoid having a ThreadAbortException * between the return from DangerousAddRef and the assignement to release_last */ bool release = false; waitHandles [i].SafeWaitHandle.DangerousAddRef (ref release); release_last = i; } } if ((context != null) && context.IsWaitNotificationRequired ()) { IntPtr[] handles = new IntPtr[waitHandles.Length]; for (int i = 0; i < waitHandles.Length; ++i) handles[i] = waitHandles[i].SafeWaitHandle.DangerousGetHandle (); return context.Wait ( handles, false, (int)millisecondsTimeout ); } else { unsafe { IntPtr* handles = stackalloc IntPtr[waitHandles.Length]; for (int i = 0; i < waitHandles.Length; ++i) handles[i] = waitHandles[i].SafeWaitHandle.DangerousGetHandle (); return Wait_internal (handles, waitHandles.Length, WaitAll, millisecondsTimeout); } } } finally { for (int i = release_last; i >= 0; --i) { waitHandles [i].SafeWaitHandle.DangerousRelease (); } #if !DISABLE_REMOTING if (exitContext) SynchronizationAttribute.EnterContext (); #endif } }
static int WaitMultiple(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext, bool WaitAll) { if (waitHandles.Length > MaxWaitHandles) { return(WAIT_FAILED); } int release_last = -1; try { #if !DISABLE_REMOTING if (exitContext) { SynchronizationAttribute.ExitContext(); } #endif for (int i = 0; i < waitHandles.Length; ++i) { try {} finally { /* we have to put it in a finally block, to avoid having a ThreadAbortException * between the return from DangerousAddRef and the assignement to release_last */ bool release = false; waitHandles [i].SafeWaitHandle.DangerousAddRef(ref release); release_last = i; } } unsafe { IntPtr *handles = stackalloc IntPtr[waitHandles.Length]; for (int i = 0; i < waitHandles.Length; ++i) { handles[i] = waitHandles[i].SafeWaitHandle.DangerousGetHandle(); } return(Wait_internal(handles, waitHandles.Length, WaitAll, millisecondsTimeout)); } } finally { for (int i = release_last; i >= 0; --i) { waitHandles [i].SafeWaitHandle.DangerousRelease(); } #if !DISABLE_REMOTING if (exitContext) { SynchronizationAttribute.EnterContext(); } #endif } }
public void ValueExample() { // Get the SynchronizationAttribute applied to the class. SynchronizationAttribute attribute = (SynchronizationAttribute)Attribute.GetCustomAttribute( this.GetType(), typeof(SynchronizationAttribute), false); // Display the value of the attribute's Value property. Console.WriteLine("SynchronizationAttribute.Value: {0}", attribute.Value); }
public void DeserializeKnownValue() { MemoryStream ms = new MemoryStream(serialized_sync_attr); #if TARGET_JVM BinaryFormatter bf = (BinaryFormatter)vmw.@internal.remoting.BinaryFormatterUtils.CreateBinaryFormatter(false); #else BinaryFormatter bf = new BinaryFormatter(); #endif // TARGET_JVM SynchronizationAttribute sa = (SynchronizationAttribute)bf.Deserialize(ms); Assert.IsTrue(sa.IsReEntrant, "IsReEntrant"); Assert.IsFalse(sa.Locked, "Locked"); }
public void SerializationRoundtrip() { SynchronizationAttribute sa = new SynchronizationAttribute(SynchronizationAttribute.NOT_SUPPORTED, true); BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, sa); ms.Position = 0; SynchronizationAttribute clone = (SynchronizationAttribute)bf.Deserialize(ms); Assert.IsTrue(sa.IsReEntrant, "IsReEntrant"); Assert.IsFalse(sa.Locked, "Locked"); }
static int WaitMultiple(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext, bool WaitAll) { #if MONOTOUCH if (exitContext) { throw new NotSupportedException("exitContext == true is not supported"); } #endif int release_last = -1; try { if (exitContext) { SynchronizationAttribute.ExitContext(); } for (int i = 0; i < waitHandles.Length; ++i) { try { } finally { /* we have to put it in a finally block, to avoid having a ThreadAbortException * between the return from DangerousAddRef and the assignement to release_last */ bool release = false; waitHandles [i].SafeWaitHandle.DangerousAddRef(ref release); release_last = i; } } if (WaitAll) { return(WaitAll_internal(waitHandles, millisecondsTimeout, exitContext)); } else { return(WaitAny_internal(waitHandles, millisecondsTimeout, exitContext)); } } finally { for (int i = release_last; i >= 0; --i) { waitHandles [i].SafeWaitHandle.DangerousRelease(); } if (exitContext) { SynchronizationAttribute.EnterContext(); } } }
public static bool Wait(object obj, TimeSpan timeout, bool exitContext) { try { if (exitContext) { #if MONOTOUCH throw new NotSupportedException ("exitContext == true is not supported"); #else SynchronizationAttribute.ExitContext (); #endif } return Wait (obj, timeout); } finally { if (exitContext) SynchronizationAttribute.EnterContext (); } }
public void SetLocked() { SynchronizationAttribute sa = new SynchronizationAttribute(SynchronizationAttribute.REQUIRES_NEW); sa.Locked = true; Assert.IsTrue(sa.Locked, "Locked"); sa.Locked = false; Assert.IsFalse(sa.Locked, "Locked"); sa.Locked = true; Assert.IsTrue(sa.Locked, "Locked"); sa.Locked = true; Assert.IsTrue(sa.Locked, "Locked"); sa.Locked = false; Assert.IsFalse(sa.Locked, "Locked"); }
public static bool Wait(object obj, TimeSpan timeout, bool exitContext) { try { if (exitContext) { SynchronizationAttribute.ExitContext(); } return(Wait(obj, timeout)); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } } }
public static bool Wait(object obj, int millisecondsTimeout, bool exitContext) { try { if (exitContext) { SynchronizationAttribute.ExitContext(); } return(Wait(obj, millisecondsTimeout)); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } } }
public virtual bool WaitOne(int millisecondsTimeout, bool exitContext) { CheckDisposed(); try { if (exitContext) { SynchronizationAttribute.ExitContext(); } return(WaitOne_internal(os_handle, millisecondsTimeout, exitContext)); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } } }
public static bool Wait(object obj, TimeSpan timeout, bool exitContext) { try { #if !DISABLE_REMOTING if (exitContext) { SynchronizationAttribute.ExitContext(); } #endif return(Wait(obj, timeout)); } finally { #if !DISABLE_REMOTING if (exitContext) { SynchronizationAttribute.EnterContext(); } #endif } }
/// <summary>Releases the lock on an object and blocks the current thread until it reacquires the lock. If the specified time-out interval elapses, the thread enters the ready queue. Optionally exits the synchronization domain for the synchronized context before the wait and reacquires the domain afterward.</summary> /// <returns>true if the lock was reacquired before the specified time elapsed; false if the lock was reacquired after the specified time elapsed. The method does not return until the lock is reacquired.</returns> /// <param name="obj">The object on which to wait. </param> /// <param name="timeout">A <see cref="T:System.TimeSpan" /> representing the amount of time to wait before the thread enters the ready queue. </param> /// <param name="exitContext">true to exit and reacquire the synchronization domain for the context (if in a synchronized context) before the wait; otherwise, false. </param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="obj" /> parameter is null. </exception> /// <exception cref="T:System.Threading.SynchronizationLockException">Wait is not invoked from within a synchronized block of code. </exception> /// <exception cref="T:System.Threading.ThreadInterruptedException">The thread that invokes Wait is later interrupted from the waiting state. This happens when another thread calls this thread's <see cref="M:System.Threading.Thread.Interrupt" /> method. </exception> /// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="timeout" /> parameter is negative and does not represent <see cref="F:System.Threading.Timeout.Infinite" /> (–1 millisecond), or is greater than <see cref="F:System.Int32.MaxValue" />. </exception> /// <filterpriority>1</filterpriority> public static bool Wait(object obj, TimeSpan timeout, bool exitContext) { bool result; try { if (exitContext) { SynchronizationAttribute.ExitContext(); } result = Monitor.Wait(obj, timeout); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } } return(result); }