public void Stop() { _guardDataSaver.Stop(); _tokenSource.Cancel(); _taskForGuardDataSaver.Wait(); if (_report.Count != 0) { DataSaving?.Invoke(); } }
public void Start() { _tokenSource = new CancellationTokenSource(); var cancellation = _tokenSource.Token; _taskForGuardDataSaver = new Task((token) => { CancellationToken t = (CancellationToken)token; _guardDataSaver = new Guard( actionToDoEveryTick: () => DataSaving?.Invoke(), secondsToCountdown: _dataSavingIntervalSec ); _guardDataSaver.Start(); }, cancellation); _taskForGuardDataSaver.Start(); }