@page "/counter"
@rendermode InteractiveServer
@using System.Threading
Current count: @currentCount
@* @if (currentCount % 2 == 0) {You win!
} *@ @code { private static int currentCount = 0; private void IncrementCount() { // 启动后台任务进行计数 _ = Task.Run(async () => { while (true) { await Task.Delay(1000); currentCount++; await InvokeAsync(() => { StateHasChanged(); }); } }); } }