Skip to content

JS Interop only works on main thread when using multiple threads #799

Open
@Rippletank

Description

@Rippletank

UnoWASMnet80TheadsAndJSInterop.zip

Background

Working on porting an existing app to Uno platform. Have implemented javascript replacements for many features not currently supported by WASM, such as cryptography, database, speech etc.

Issue

Using the JSImportAttribute and JSHost.ImportAsync works fine on the main thread but throws an exception "Please use dedicated worker for working with Javacsript interop" when run on a thread pool thread.

The exception seems to be thrown because there is no CurrentJSSynchronizationContext for the given thread in JSSynchronizationContext .

I can't find where this is actually set for the main thread. There is a WebWorker class which does install the required synchronisation contexts. However, I can't find any way to access this class anywhere. I did also try a UseWasmExperimental setting that was mentioned somewhere for .net7.0 but this didn't appear to do anything.

Reproduction

Attached project is minimal reproduction of the issue (reporting to console) for a simple synchronous and async call.

Workaround

Redirect all interop calls to main thread. However, this means that the main thread is blocked and animations stutter and controls are unresponsive as would be expected. I have set up a JS worker to handle the database calls once on the JS side.

Solution?

I am not familiar with how the Dotnet and Uno Platform git repos correspond with what is packaged, but is it possible to make the WebWorker class accessible? Failing that, is there any other way of getting more than one thread setup to run JS calls?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions