namespace System.Threading
{
[ComVisible (true)]
- public abstract class WaitHandle : MarshalByRefObject, IDisposable
+ [StructLayout (LayoutKind.Sequential)]
+ public abstract class WaitHandle
+ : MarshalByRefObject, IDisposable
{
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern bool WaitAll_internal(WaitHandle[] handles, int ms, bool exitContext);
throw new ArgumentOutOfRangeException ("millisecondsTimeout");
try {
- if (exitContext) SynchronizationAttribute.ExitContext ();
+ if (exitContext) {
+#if MONOTOUCH
+ throw new NotSupportedException ("exitContext == true is not supported");
+#else
+ SynchronizationAttribute.ExitContext ();
+#endif
+ }
return(WaitAll_internal(waitHandles, millisecondsTimeout, false));
}
finally {
throw new ArgumentOutOfRangeException ("timeout");
try {
- if (exitContext) SynchronizationAttribute.ExitContext ();
+ if (exitContext) {
+#if MONOTOUCH
+ throw new NotSupportedException ("exitContext == true is not supported");
+#else
+ SynchronizationAttribute.ExitContext ();
+#endif
+ }
return (WaitAll_internal (waitHandles, (int) ms, exitContext));
}
finally {
throw new ArgumentOutOfRangeException ("millisecondsTimeout");
try {
- if (exitContext) SynchronizationAttribute.ExitContext ();
+ if (exitContext) {
+#if MONOTOUCH
+ throw new NotSupportedException ("exitContext == true is not supported");
+#else
+ SynchronizationAttribute.ExitContext ();
+#endif
+ }
return(WaitAny_internal(waitHandles, millisecondsTimeout, exitContext));
}
finally {
throw new ArgumentOutOfRangeException ("timeout");
try {
- if (exitContext) SynchronizationAttribute.ExitContext ();
+ if (exitContext) {
+#if MONOTOUCH
+ throw new NotSupportedException ("exitContext == true is not supported");
+#else
+ SynchronizationAttribute.ExitContext ();
+#endif
+ }
return (WaitAny_internal(waitHandles, (int) ms, exitContext));
}
finally {
// FIXME
}
- public virtual void Close() {
+ public virtual void Close ()
+ {
Dispose(true);
- GC.SuppressFinalize (this);
}
-#if NET_4_0
public void Dispose ()
{
Close ();
}
-#endif
public const int WaitTimeout = 258;
protected virtual void Dispose (bool explicitDisposing)
{
if (!disposed){
- disposed = true;
//
// This is only the case if the handle was never properly initialized
return;
lock (this){
+ if (disposed)
+ return;
+
+ disposed = true;
if (safe_wait_handle != null)
safe_wait_handle.Dispose ();
}
bool release = false;
try {
- if (exitContext)
+ if (exitContext) {
+#if !MONOTOUCH
SynchronizationAttribute.ExitContext ();
+#endif
+ }
safe_wait_handle.DangerousAddRef (ref release);
return (WaitOne_internal(safe_wait_handle.DangerousGetHandle (), millisecondsTimeout, exitContext));
} finally {
+#if !MONOTOUCH
if (exitContext)
SynchronizationAttribute.EnterContext ();
+#endif
if (release)
safe_wait_handle.DangerousRelease ();
}
bool release = false;
try {
- if (exitContext)
+ if (exitContext) {
+#if !MONOTOUCH
SynchronizationAttribute.ExitContext ();
+#endif
+ }
safe_wait_handle.DangerousAddRef (ref release);
return (WaitOne_internal(safe_wait_handle.DangerousGetHandle (), (int) ms, exitContext));
}
finally {
+#if !MONOTOUCH
if (exitContext)
SynchronizationAttribute.EnterContext ();
+#endif
if (release)
safe_wait_handle.DangerousRelease ();
}
protected static readonly IntPtr InvalidHandle = (IntPtr) (-1);
bool disposed = false;
-
- void IDisposable.Dispose() {
- Dispose(true);
- // Take yourself off the Finalization queue
- GC.SuppressFinalize(this);
- }
-
- ~WaitHandle() {
- Dispose(false);
- }
}
}