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 { bootstrapper.configure(context); @@ -138,6 +145,7 @@ namespace Uno.WebAssembly.Bootstrap { onConfigLoaded: this.onConfigLoaded, onDotnetReady: this.onDotnetReady, onAbort: this.onAbort, + pthreadPoolInitialSize: 2, exports: ["IDBFS", "FS"].concat(this._unoConfig.emcc_exported_runtime_methods), onDownloadResourceProgress: (resourcesLoaded: number, totalResources: number) => this.reportDownloadResourceProgress(resourcesLoaded, totalResources), }; @@ -253,9 +261,9 @@ namespace Uno.WebAssembly.Bootstrap { await this.setupHotReload(); - if (this._hotReloadSupport) { - await this._hotReloadSupport.initializeHotReload(); - } + //if (this._hotReloadSupport) { + // await this._hotReloadSupport.initializeHotReload(); + //} this._runMain(this._unoConfig.uno_main, []); diff --git a/src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/HotReloadSupport.ts b/src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/HotReloadSupport.ts index 909e3399a..7c45f6c49 100644 --- a/src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/HotReloadSupport.ts +++ b/src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/HotReloadSupport.ts @@ -37,16 +37,15 @@ namespace Uno.WebAssembly.Bootstrap { (this._context).config.environmentVariables['ASPNETCORE-BROWSER-TOOLS'] || (this._context).config.environmentVariables['__ASPNETCORE_BROWSER_TOOLS']; + if (!await HotReloadSupport._initializeMethod()) { + console.warn("The application was compiled with the IL linker enabled, hot reload is disabled. See https://aka.platform.uno/wasm-il-linker for more details."); + } + let capabilities = await HotReloadSupport._getApplyUpdateCapabilitiesMethod(); + // Take the place of the internal .NET for WebAssembly APIs for metadata updates coming // from the "BrowserLink" feature. (function (Blazor) { Blazor._internal = { - initialize: function () { - if (!HotReloadSupport._initializeMethod()) { - console.warn("The application was compiled with the IL linker enabled, hot reload is disabled. See https://aka.platform.uno/wasm-il-linker for more details."); - } - }, - applyExisting: async function (): Promise { if (browserToolsVariable == "true") @@ -62,13 +61,11 @@ 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 = {})); diff --git a/src/Uno.Wasm.Tests.Shared/Runtime.cs b/src/Uno.Wasm.Tests.Shared/Runtime.cs index bcea77fee..26ce4c0ce 100644 --- a/src/Uno.Wasm.Tests.Shared/Runtime.cs +++ b/src/Uno.Wasm.Tests.Shared/Runtime.cs @@ -3,6 +3,7 @@ using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Runtime.InteropServices.JavaScript; +using System.Threading.Tasks; namespace WebAssembly { @@ -11,7 +12,7 @@ internal sealed class Runtime /// /// Invokes Javascript code in the hosting environment /// - internal static string InvokeJS(string str) + internal static Task InvokeJS(string str) { Console.WriteLine($"Invoking {str}"); return Interop.InvokeJS(str); @@ -21,6 +22,6 @@ internal static string InvokeJS(string str) internal static partial class Interop { [JSImport("globalThis.Uno.WebAssembly.Bootstrap.Bootstrapper.invokeJS")] - public static partial string InvokeJS(string value); + public static partial Task InvokeJS(string value); } } diff --git a/src/Uno.Wasm.Threads.Shared/Program.cs b/src/Uno.Wasm.Threads.Shared/Program.cs index a330f9dd2..1efff9b8c 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,8 +42,9 @@ 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')"); + _ = Runtime.InvokeJS("Interop.appendResult('Startup')"); Run(); @@ -55,7 +57,7 @@ private static void OnTick(object state) if (_event.WaitOne(10) && _mainThreadInvoked) { var r = $"Done {_messages.Count} results (_mainThreadInvoked:{_mainThreadInvoked})"; - Runtime.InvokeJS($"Interop.appendResult('{r}')"); + _ = Runtime.InvokeJS($"Interop.appendResult('{r}')"); Console.WriteLine($"[tid:{Thread.CurrentThread.ManagedThreadId}]: {r}"); _timer.Dispose(); } @@ -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}]"); - 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..50684802b 100644 --- a/src/Uno.Wasm.Threads.Shared/WasmScripts/test.js +++ b/src/Uno.Wasm.Threads.Shared/WasmScripts/test.js @@ -3,16 +3,9 @@ }); var Interop = { - appendResult: function (str) { + appendResult: async function (str) { var txt = document.createTextNode(str); var parent = document.getElementById('results'); 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 +