Aspnetcore: WASM: WASM doesn't support threading

Created on 8 Feb 2018  路  7Comments  路  Source: dotnet/aspnetcore

I have a scenario where I like to have a socket connection in my c# part.
When new data arrives the html should be updated.
I tried to simulate this using a simple timer.
This results in a error message
WASM: WASM doesn't support threading

I don't need a timer in my code, but when there is no threading,
will asynchronous socket connections work properly?

area-blazor

Most helpful comment

If you want to be called back after a timeout, Task.Delay should work.

Note that Mono WASM will be single-threaded, at least for the forseeable future. So you can do async, but only one execution thread will proceed concurrently and others will be queued. It's the same model that JavaScript has always used.

All 7 comments

@StephanHartmann async is a promise/callback and doesn't necessarily need threading
FYI https://stackoverflow.com/questions/15148852/async-await-vs-threads

I implemented the timer this way ...
timer = new Timer(TimerCallback, null, 5000, 1000);
For my understanding ...
The problem is not the TimerCallback - Function, but the fact that the timer uses threading to do his timing job, right ?

@StephanHartmann yes; that's correct, timers use threading; a possible work around could be create a javascript timer, and call into the C# code from the javascript

ok, thank you

If you want to be called back after a timeout, Task.Delay should work.

Note that Mono WASM will be single-threaded, at least for the forseeable future. So you can do async, but only one execution thread will proceed concurrently and others will be queued. It's the same model that JavaScript has always used.

@SteveSandersonMS I assume that it's even the same thread that WASM and Javascript uses, correct? (ie no synchronization needs to be considered)

Yes

Was this page helpful?
0 / 5 - 0 ratings