Live demo | Full example on GitHub
You add a button that does some real work. Someone clicks it, and the whole page stops. Nothing scrolls and no other button responds until the work is done.
A Blazor WebAssembly app normally runs its C# on the same thread the browser uses to draw the page. While your loop runs, the browser cannot draw.
Task.Run does not help here. Without WebAssembly threading, it queues the work on that same thread.
The browser's answer is a Web Worker: a separate thread with its own memory. In this article we move a slow C# method into one and measure what changes. You need the .NET 10 SDK and a browser.
Something slow
This counts prime numbers the hard way:
namespace WebWorkers ;
public static class Primes { /// <summary>Counts the primes up to and including <paramref name="limit"/>.…