'ContinueWith and TaskScheduler.FromCurrentSynchronizationContext on blazor wasm

I'm porting old WinForms code to blazor that uses Task.ContinueWith() passing TaskScheduler.FromCurrentSynchronizationContext() as parameter to run the continuation on the UI thread.

It works fine on blazor server, but throws an exception on blazor wasm:

System.InvalidOperationException: The current SynchronizationContext may not be used as a TaskScheduler.

SynchronizationContext.Current is null in blazor wasm, probably because is not needed as the browser is single threaded, but why not to set a dummy SynchronizationContext for compatibility? Can I do it myself?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source