@using WorkerLib
@using BlazorWasmApp.Workers
@inject IJSRuntime JSRuntime
@implements IAsyncDisposable
<h3>WebWorker Demo</h3>
<button @onclick="InitAndTest">Test WebWorker</button>
<p>Status: @status</p>
<p>Add result: @addResult</p>
<p>Greet result: @greetResult</p>
<p>JSON result: @jsonResult</p>
@code {
private WebWorkerClient? worker;
private string status = "Not started";
private string addResult = "", greetResult = "", jsonResult = "";
private async Task InitAndTest()
{
status = "Initializing...";
worker = await WebWorkerClient.CreateAsync(JSRuntime);
status = "Ready";
var sum = await worker.InvokeAsync<int>("BlazorWasmApp.Workers.MyWorkerMethods.Add", [5, 3]);
addResult = sum.ToString();
var greeting = await worker.InvokeAsync<string>("BlazorWasmApp.Workers.MyWorkerMethods.Greet", ["World"]);
greetResult = greeting;
var person = await worker.InvokeAsync<Person>("BlazorWasmApp.Workers.MyWorkerMethods.GetPersonJson", []);
jsonResult = $"{person.Name}, Age {person.Age}";
}
public async ValueTask DisposeAsync()
{
if (worker != null) await worker.DisposeAsync();
}
}
REGRESSION INFO No, web worker is a new feature introduced in Preview 2. Also repro on 11.0 Preview 3
INSTALL STEPS
Platform
Repro Steps
File > New Project > Select "Blazor WebAssembly Standalone App" > Give name "BlazorWasmApp" > Next > select ".NET 11.0" > Create
Right-click the Solution > Add > New Project > Select ".NET Web Worker" template > Give name "WorkerLib" > Create
Right-click the BlazorWasmApp project > Add > Project Reference > Check WorkerLib > OK
Open BlazorWasmApp.csproj and add inside :
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>Also add:
Create a new file Workers/MyWorkerMethods.cs with the following content:
Open
Pages/Home.razorand add the following code below the existing content:Place a breakpoint at the
addResult = sum.ToString();line in Pages/Home.razorRun the project (F5).
After the webpage loads successfully, click the Test WebWorker button
Note:
Actual Result

The WebWorker hang when debugging Blazor WASM apps in VS
Error Log