Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSRuntime.InvokeAsync("open", ...) throws TaskCanceledException

In my blazor-server-side app I am calling JSRuntime.InvokeAsync to open static content in a popup window:

await _jsRuntime.InvokeAsync<object>("open", "/help/help.html", "_blank");

It works, but after some time (probably a timeout?) a TaskCanceledException is thrown. I tried calling InvokeVoidAsync, but the effect is the same. I can fix this by catching and ignoring the exception or by removing "await", but I was hoping for a cleaner solution that does not give me complier warnings.

like image 808
Stefan Avatar asked Sep 01 '25 03:09

Stefan


1 Answers

Try specify cancellationToken as CancellationToken.None

await _jsRuntime.InvokeAsync<object>("open", System.Threading.CancellationToken.None, "/help/help.html", "_blank");

A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts (DefaultAsyncTimeout) from being applied.

Documenation here

like image 76
adaraz Avatar answered Sep 04 '25 15:09

adaraz