36 lines
722 B
C#
36 lines
722 B
C#
using System.Diagnostics;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace WebAssembly.PageComponents;
|
|
|
|
public class CounterBase : ComponentBase
|
|
{
|
|
public int CurrentCount { get; private set; }
|
|
public bool Cancel { get; private set; }
|
|
public Stopwatch Stopwatch { get; } = new();
|
|
|
|
public async Task Start()
|
|
{
|
|
Stopwatch.Start();
|
|
Cancel = false;
|
|
while (!Cancel)
|
|
{
|
|
CurrentCount++;
|
|
StateHasChanged();
|
|
await Task.Delay(10);
|
|
}
|
|
Stopwatch.Stop();
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
Cancel = true;
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
Cancel = true;
|
|
CurrentCount = 0;
|
|
Stopwatch.Reset();
|
|
}
|
|
} |