fix group panel, restarts with dtr entry

This commit is contained in:
rootdarkarchon
2023-06-27 18:56:05 +02:00
parent 222e8bb888
commit 2473087da4
2 changed files with 47 additions and 37 deletions

View File

@@ -10,12 +10,11 @@ namespace MareSynchronos.UI;
public sealed class DtrEntry : IDisposable, IHostedService
{
private readonly DtrBarEntry _entry;
private readonly ConfigurationServiceBase<MareConfig> _configService;
private readonly PairManager _pairManager;
private readonly ApiController _apiController;
private readonly CancellationTokenSource _cancellationTokenSource = new();
private readonly ConfigurationServiceBase<MareConfig> _configService;
private readonly DtrBarEntry _entry;
private readonly PairManager _pairManager;
private Task? _runTask;
private string? _text;
@@ -34,6 +33,44 @@ public sealed class DtrEntry : IDisposable, IHostedService
_entry.Dispose();
}
public Task StartAsync(CancellationToken cancellationToken)
{
_runTask = Task.Run(RunAsync, _cancellationTokenSource.Token);
return Task.CompletedTask;
}
public async Task StopAsync(CancellationToken cancellationToken)
{
_cancellationTokenSource.Cancel();
try
{
await _runTask!.ConfigureAwait(false);
}
catch (OperationCanceledException) { }
finally
{
_cancellationTokenSource.Dispose();
Clear();
}
}
private void Clear()
{
_text = null;
_entry.Shown = false;
_entry.Text = null;
}
private async Task RunAsync()
{
while (!_cancellationTokenSource.IsCancellationRequested)
{
Update();
await Task.Delay(1000, _cancellationTokenSource.Token).ConfigureAwait(false);
}
}
private void Update()
{
if (!_configService.Current.EnableDtrEntry)
@@ -65,35 +102,4 @@ public sealed class DtrEntry : IDisposable, IHostedService
_entry.Text = text;
}
}
private void Clear()
{
_text = null;
_entry.Shown = false;
_entry.Text = null;
}
private async Task RunAsync()
{
while (!_cancellationTokenSource.IsCancellationRequested)
{
Update();
await Task.Delay(1000, _cancellationTokenSource.Token).ConfigureAwait(false);
}
}
public Task StartAsync(CancellationToken cancellationToken)
{
_runTask = Task.Run(RunAsync, _cancellationTokenSource.Token);
return Task.CompletedTask;
}
public async Task StopAsync(CancellationToken cancellationToken)
{
_cancellationTokenSource.Cancel();
await _runTask!.ConfigureAwait(false);
_cancellationTokenSource.Dispose();
Clear();
}
}