split code and html
This commit is contained in:
36
WebAssembly/PageComponents/CounterBase.cs
Normal file
36
WebAssembly/PageComponents/CounterBase.cs
Normal 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user