diff --git a/build/ci/stage-build-linux-tests.yml b/build/ci/stage-build-linux-tests.yml index 380ec5ac8..40263bb5a 100644 --- a/build/ci/stage-build-linux-tests.yml +++ b/build/ci/stage-build-linux-tests.yml @@ -66,7 +66,6 @@ jobs: "$(build.sourcesdirectory)/src/Uno.Wasm.Threads/bin/Release/net9.0/publish/wwwroot" \ "$(build.sourcesdirectory)/src/Uno.Wasm.Threading.UITests" "http://localhost:8000/" displayName: Threading UI Tests - condition: eq( variables['THREAD_TESTING'], 'true' ) env: BUILD_SOURCESDIRECTORY: "$(build.sourcesdirectory)" @@ -82,7 +81,6 @@ jobs: "$(build.sourcesdirectory)/src/Uno.Wasm.Threads.Aot/bin/Release/net9.0/publish/wwwroot" \ "$(build.sourcesdirectory)/src/Uno.Wasm.Threading.UITests" "http://localhost:8000/" displayName: Threading AOT UI Tests - condition: eq( variables['THREAD_TESTING'], 'true' ) env: BUILD_SOURCESDIRECTORY: "$(build.sourcesdirectory)" diff --git a/build/ci/stage-build-windows-tests.yml b/build/ci/stage-build-windows-tests.yml index d73463285..69313ce39 100644 --- a/build/ci/stage-build-windows-tests.yml +++ b/build/ci/stage-build-windows-tests.yml @@ -241,7 +241,6 @@ jobs: "http://localhost:8000/" displayName: Threading Tests - condition: eq( variables['THREAD_TESTING'], 'true' ) env: BUILD_SOURCESDIRECTORY: "$(build.sourcesdirectory)" @@ -258,7 +257,6 @@ jobs: "$(build.sourcesdirectory)\src\Uno.Wasm.Threading.UITests" ` "http://localhost:8000/" displayName: Threading AOT Tests - condition: eq( variables['THREAD_TESTING'], 'true' ) env: BUILD_SOURCESDIRECTORY: "$(build.sourcesdirectory)" diff --git a/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets b/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets index 845a18d2d..7630c7097 100644 --- a/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets +++ b/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets @@ -202,7 +202,7 @@ true - <_WasmPThreadPoolInitialSize Condition=" '$(WasmShellPThreadsPoolSize)' == 'true' ">true + <_WasmPThreadPoolInitialSize Condition=" '$(WasmShellPThreadsPoolSize)' == '' ">2 { if (browserToolsVariable == "true") @@ -62,19 +62,15 @@ namespace Uno.WebAssembly.Bootstrap { }, getApplyUpdateCapabilities: function () { - Blazor._internal.initialize(); - return HotReloadSupport._getApplyUpdateCapabilitiesMethod(); + return capabilities; }, applyHotReload: function (moduleId: any, metadataDelta: any, ilDelta: any, pdbDelta: any, updatedTypes: any) { - Blazor._internal.initialize(); - return HotReloadSupport._applyHotReloadDeltaMethod(moduleId, metadataDelta, ilDelta, pdbDelta || "", updatedTypes || []); + HotReloadSupport._applyHotReloadDeltaMethod(moduleId, metadataDelta, ilDelta, pdbDelta || "", updatedTypes || []); } }; })((window).Blazor || ((window).Blazor = {})); - // Apply pending updates caused by a browser refresh - (window).Blazor._internal.initialize(); await (window).Blazor._internal.applyExisting(); } } diff --git a/src/Uno.Wasm.MetadataUpdater/WebAssemblyHotReload.cs b/src/Uno.Wasm.MetadataUpdater/WebAssemblyHotReload.cs index d192e0f5f..7ef190e5a 100644 --- a/src/Uno.Wasm.MetadataUpdater/WebAssemblyHotReload.cs +++ b/src/Uno.Wasm.MetadataUpdater/WebAssemblyHotReload.cs @@ -29,7 +29,7 @@ public static partial class WebAssemblyHotReload }; [JSExport] - internal static bool Initialize() + internal static async Task Initialize() { bool.TryParse(Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_LOG_METADATA_UPDATES"), out _debugEnabled); @@ -62,7 +62,7 @@ internal static bool Initialize() /// For framework use only. /// [JSExport] - public static void ApplyHotReloadDelta(string moduleIdString, string metadataDelta, string ilDeta, string pdbDelta, int[] updatedTypes) + public static async Task ApplyHotReloadDelta(string moduleIdString, string metadataDelta, string ilDeta, string pdbDelta, int[] updatedTypes) { if (_linkerEnabled) { @@ -93,7 +93,7 @@ public static void ApplyHotReloadDelta(string moduleIdString, string metadataDel /// For framework use only. /// [JSExport] - public static string GetApplyUpdateCapabilities() + public static async Task GetApplyUpdateCapabilities() { if (_debugEnabled) { diff --git a/src/Uno.Wasm.Threads.Shared/Program.cs b/src/Uno.Wasm.Threads.Shared/Program.cs index a330f9dd2..c4db60327 100644 --- a/src/Uno.Wasm.Threads.Shared/Program.cs +++ b/src/Uno.Wasm.Threads.Shared/Program.cs @@ -34,6 +34,7 @@ public static class Program private static List _messages = new List(); private static bool _mainThreadInvoked = false; private static Timer _timer; + private static SynchronizationContext _jsContext = SynchronizationContext.Current; static void Main() { @@ -41,6 +42,7 @@ static void Main() Console.WriteLine($"Runtime Version: " + RuntimeInformation.FrameworkDescription); Console.WriteLine($"Runtime Mode: " + runtimeMode); Console.WriteLine($"TID: {Thread.CurrentThread.ManagedThreadId}"); + Console.WriteLine($"SynchronizationContext: {_jsContext}"); Runtime.InvokeJS("Interop.appendResult('Startup')"); @@ -81,7 +83,7 @@ void logMessage(string message) int index = Interlocked.Increment(ref counter); lock (_gate) { - _messages.Add($"[tid:{Thread.CurrentThread.ManagedThreadId}]: {index} / {message}"); + _messages.Add($"[tid:{Thread.CurrentThread.ManagedThreadId}][ctx:{SynchronizationContext.Current?.ToString()}]: {index} / {message}"); } } @@ -92,21 +94,25 @@ void DoWork(string name) if ((i % 2000) == 0) { - WebAssembly.JSInterop.InternalCalls.InvokeOnMainThread(); + Console.WriteLine("InvokeOnMainThread1"); + _jsContext.Post(_ => MainThreadCallback(), null); } } } +#pragma warning disable CA1416 // Validate platform compatibility new Thread(_ => { - Console.WriteLine($"Starting thread [tid:{Thread.CurrentThread.ManagedThreadId}]"); + Console.WriteLine($"Starting thread [tid:{Thread.CurrentThread.ManagedThreadId}] [ctx:{SynchronizationContext.Current?.ToString()}]"); - WebAssembly.JSInterop.InternalCalls.InvokeOnMainThread(); + _jsContext.Post(_ => MainThreadCallback(), null); + Console.WriteLine("InvokeOnMainThread2"); DoWork("thread1"); tcs.TrySetResult(true); Console.WriteLine($"Stopping thread [tid:{Thread.CurrentThread.ManagedThreadId}]"); }).Start(); +#pragma warning restore CA1416 // Validate platform compatibility await tcs.Task; @@ -114,12 +120,3 @@ void DoWork(string name) } } } - -namespace WebAssembly.JSInterop -{ - public static class InternalCalls - { - [MethodImplAttribute(MethodImplOptions.InternalCall)] - public static extern void InvokeOnMainThread(); - } -} diff --git a/src/Uno.Wasm.Threads.Shared/WasmScripts/test.js b/src/Uno.Wasm.Threads.Shared/WasmScripts/test.js index 8c378a488..a45bb99eb 100644 --- a/src/Uno.Wasm.Threads.Shared/WasmScripts/test.js +++ b/src/Uno.Wasm.Threads.Shared/WasmScripts/test.js @@ -9,10 +9,3 @@ var Interop = { parent.appendChild(txt, parent.lastChild); } }; - -var DotNet = { - invokeOnMainThread: function (str) { - let getApplyUpdateCapabilitiesMethod = BINDING.bind_static_method("[Uno.Wasm.Threads] Uno.Wasm.Sample.Program:MainThreadCallback"); - getApplyUpdateCapabilitiesMethod(); - } -} diff --git a/src/Uno.Wasm.Threads/Uno.Wasm.Threads.csproj b/src/Uno.Wasm.Threads/Uno.Wasm.Threads.csproj index 68e0524a1..a4444b2e0 100644 --- a/src/Uno.Wasm.Threads/Uno.Wasm.Threads.csproj +++ b/src/Uno.Wasm.Threads/Uno.Wasm.Threads.csproj @@ -9,6 +9,7 @@ true true +