split code and html

This commit is contained in:
2022-01-22 22:26:20 +01:00
parent 12e542800a
commit c2725eba60
2 changed files with 40 additions and 35 deletions

View File

@ -0,0 +1,36 @@
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();
}
}