@page "/counter"
@using System.Diagnostics
Current count: @_currentCount
Runtime: @_stopwatch.Elapsed.ToString("g")
@code { private int _currentCount = 0; private bool _cancel; private readonly Stopwatch _stopwatch = new(); private async Task Start() { _stopwatch.Start(); _cancel = false; while (!_cancel) { _currentCount++; StateHasChanged(); await Task.Delay(10); } _stopwatch.Stop(); } private void Stop() { _cancel = true; } private void Reset() { _cancel = true; _currentCount = 0; _stopwatch.Reset(); } }