IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ExecutorSynchronizationContext.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4
5#if FIRST_PASS == false
6
7using java.lang;
8using java.util.concurrent;
9
11{
12
16 class ExecutorSynchronizationContext : SynchronizationContext
17 {
18
22 class TaskRunnable : Runnable
23 {
24
26 readonly SendOrPostCallback post;
27 readonly object state;
28
36 public TaskRunnable(ExecutorSynchronizationContext self, SendOrPostCallback post, object state)
37 {
38 this.self = self ?? throw new ArgumentNullException(nameof(self));
39 this.post = post ?? throw new ArgumentNullException(nameof(post));
40 this.state = state;
41 }
42
43 public void run()
44 {
45 var save = Current;
46
47 try
48 {
49 SetSynchronizationContext(self);
50 post(state);
51 }
52 finally
53 {
54 SetSynchronizationContext(save);
55 }
56 }
57
58 }
59
60 readonly Executor executor;
61
67 public ExecutorSynchronizationContext(Executor executor)
68 {
69 this.executor = executor ?? throw new ArgumentNullException(nameof(executor));
70 }
71
72 public override void Post(SendOrPostCallback d, object state)
73 {
74 executor.execute(new TaskRunnable(this, d, state));
75 }
76
77 }
78
79}
80
81#endif
TaskScheduler implementation that executes tasks on a Executor.