1 // Compiler options: -langversion:future
4 using System
.Threading
;
5 using System
.Threading
.Tasks
;
7 class MyContext
: SynchronizationContext
11 public int PostCounter
;
12 public int SendCounter
;
14 public override void OperationStarted ()
17 base.OperationStarted ();
20 public override void OperationCompleted ()
23 base.OperationCompleted ();
26 public override void Post (SendOrPostCallback d
, object state
)
32 public override void Send (SendOrPostCallback d
, object state
)
40 public class TestPostContext
42 static async Task
<int> Test ()
44 return await Task
.Factory
.StartNew (() => 1);
47 public static int Main ()
49 var context
= new MyContext ();
51 SynchronizationContext
.SetSynchronizationContext (context
);
55 SynchronizationContext
.SetSynchronizationContext (null);
58 if (context
.Started
!= 0 || context
.Completed
!= 0 || context
.SendCounter
!= 0)
61 if (context
.PostCounter
!= 1)
64 Console
.WriteLine ("ok");