71 lines
1.9 KiB
C#
71 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace model
|
|
{
|
|
/*internal class Timer : IDisposable
|
|
{
|
|
private PeriodicTimer _timer;
|
|
public event EventHandler<EventArgs>? Tick;
|
|
public Timer(TimeSpan tick, TimeProvider _time_provider)
|
|
{
|
|
_timer = new PeriodicTimer(tick, _time_provider);
|
|
}
|
|
|
|
private CancellationTokenSource? _cts;
|
|
private bool disposedValue;
|
|
|
|
private async Task TickerTask()
|
|
{
|
|
_cts = new CancellationTokenSource();
|
|
while (await _timer.WaitForNextTickAsync(_cts.Token))
|
|
{
|
|
Tick?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
Task.Run(TickerTask);
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
_cts?.Cancel();
|
|
}
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (!disposedValue)
|
|
{
|
|
if (disposing)
|
|
{
|
|
// TODO: dispose managed state (managed objects)
|
|
_cts?.Dispose();
|
|
}
|
|
|
|
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
|
|
// TODO: set large fields to null
|
|
disposedValue = true;
|
|
}
|
|
}
|
|
|
|
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
|
|
// ~Timer()
|
|
// {
|
|
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
// Dispose(disposing: false);
|
|
// }
|
|
|
|
public void Dispose()
|
|
{
|
|
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
Dispose(disposing: true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}*/
|
|
}
|