[Timer] Use static CB for invoking timer callbacks.
[mono.git] / mcs / class / corlib / System.Threading / SynchronizationContext.cs
index 6daae0fe72c61c0e9cf1f9a38bc619e79f236f16..cb7369fb0ff1aa3179c45b56c47beb95d5e30154 100644 (file)
@@ -26,8 +26,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
-
 using System.Runtime.ConstrainedExecution;
 using System.Runtime.InteropServices;
 
@@ -35,6 +33,8 @@ namespace System.Threading
 {
        public class SynchronizationContext
        {
+               bool notification_required;
+
                [ThreadStatic]
                static SynchronizationContext currentContext;
                
@@ -49,7 +49,13 @@ namespace System.Threading
                
                public static SynchronizationContext Current
                {
-                       get { return currentContext; }
+                       get {
+#if NET_2_1
+                               if (currentContext == null)
+                                       currentContext = new SynchronizationContext ();
+#endif
+                               return currentContext;
+                       }
                }
 
                public virtual SynchronizationContext CreateCopy ()
@@ -57,49 +63,46 @@ namespace System.Threading
                        return new SynchronizationContext (this);
                }
 
-               [MonoTODO]
                public bool IsWaitNotificationRequired ()
                {
-                       throw new NotImplementedException ();
+                       return notification_required;
                }
 
-               [MonoTODO]
                public virtual void OperationCompleted ()
                {
-                       throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public virtual void OperationStarted ()
                {
-                       throw new NotImplementedException ();
                }
                
                public virtual void Post (SendOrPostCallback d, object state)
                {
-                       d.BeginInvoke (state, null, null);
+                       ThreadPool.QueueUserWorkItem (new WaitCallback (d), state);
                }
                
                public virtual void Send (SendOrPostCallback d, object state)
                {
                        d (state);
                }
-
-               [Obsolete ("does not exists anymore in 2.0 beta2")]
-               public virtual void SendOrPost (SendOrPostCallback d, object state)
-               {
-                       Send (d, state);
-               }
                
-               [MonoTODO]
                public static void SetSynchronizationContext (SynchronizationContext syncContext)
                {
-                       throw new NotImplementedException ();
+                       currentContext = syncContext;
+               }
+
+#if NET_2_1
+               [Obsolete]
+               public static void SetThreadStaticContext (SynchronizationContext syncContext)
+               {
+                       currentContext = syncContext;
                }
+#endif
 
                [MonoTODO]
                protected void SetWaitNotificationRequired ()
                {
+                       notification_required = true;
                        throw new NotImplementedException ();
                }
 
@@ -120,5 +123,3 @@ namespace System.Threading
                }
        }
 }
-
-#endif