@@ -34,13 +34,15 @@ public static class Program
34
34
private static List < string > _messages = new List < string > ( ) ;
35
35
private static bool _mainThreadInvoked = false ;
36
36
private static Timer _timer ;
37
+ private static SynchronizationContext _jsContext = SynchronizationContext . Current ;
37
38
38
39
static void Main ( )
39
40
{
40
41
var runtimeMode = Environment . GetEnvironmentVariable ( "UNO_BOOTSTRAP_MONO_RUNTIME_MODE" ) ;
41
42
Console . WriteLine ( $ "Runtime Version: " + RuntimeInformation . FrameworkDescription ) ;
42
43
Console . WriteLine ( $ "Runtime Mode: " + runtimeMode ) ;
43
44
Console . WriteLine ( $ "TID: { Thread . CurrentThread . ManagedThreadId } ") ;
45
+ Console . WriteLine ( $ "SynchronizationContext: { _jsContext } ") ;
44
46
45
47
Runtime . InvokeJS ( "Interop.appendResult('Startup')" ) ;
46
48
@@ -92,34 +94,29 @@ void DoWork(string name)
92
94
93
95
if ( ( i % 2000 ) == 0 )
94
96
{
95
- WebAssembly . JSInterop . InternalCalls . InvokeOnMainThread ( ) ;
97
+ Console . WriteLine ( "InvokeOnMainThread1" ) ;
98
+ _jsContext . Post ( _ => MainThreadCallback ( ) , null ) ;
96
99
}
97
100
}
98
101
}
99
102
103
+ #pragma warning disable CA1416 // Validate platform compatibility
100
104
new Thread ( _ =>
101
105
{
102
106
Console . WriteLine ( $ "Starting thread [tid:{ Thread . CurrentThread . ManagedThreadId } ]") ;
103
107
104
- WebAssembly . JSInterop . InternalCalls . InvokeOnMainThread ( ) ;
108
+ _jsContext . Post ( _ => MainThreadCallback ( ) , null ) ;
109
+ Console . WriteLine ( "InvokeOnMainThread2" ) ;
105
110
106
111
DoWork ( "thread1" ) ;
107
112
tcs . TrySetResult ( true ) ;
108
113
Console . WriteLine ( $ "Stopping thread [tid:{ Thread . CurrentThread . ManagedThreadId } ]") ;
109
114
} ) . Start ( ) ;
115
+ #pragma warning restore CA1416 // Validate platform compatibility
110
116
111
117
await tcs . Task ;
112
118
113
119
_event . Set ( ) ;
114
120
}
115
121
}
116
122
}
117
-
118
- namespace WebAssembly . JSInterop
119
- {
120
- public static class InternalCalls
121
- {
122
- [ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
123
- public static extern void InvokeOnMainThread ( ) ;
124
- }
125
- }
0 commit comments