* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / AsyncMethodResult.cs
index 92869ad3a07a49512929fd56d604b01a8c55f485..8c52ca71dcc6c94b691e43cf345a54e651512a49 100644 (file)
@@ -30,14 +30,14 @@ namespace System.Windows.Forms {
 
        internal class AsyncMethodResult : IAsyncResult {
 
-               private Mutex handle;
+               private ManualResetEvent handle;
                private object state;
                private bool completed;
                private object return_value;
 
                public AsyncMethodResult ()
                {
-                       handle = new Mutex ();
+                       handle = new ManualResetEvent (false);
                }
 
                public virtual WaitHandle AsyncWaitHandle {
@@ -67,6 +67,10 @@ namespace System.Windows.Forms {
                
                public object EndInvoke ()
                {
+                       lock (this) {
+                               if (completed)
+                                       return return_value;
+                       }
                        handle.WaitOne ();
                        return return_value;
                }
@@ -76,7 +80,7 @@ namespace System.Windows.Forms {
                        lock (this) {
                                completed = true;
                                return_value = result;
-                               handle.ReleaseMutex ();
+                               handle.Set ();
                        }
                }
        }