using Microsoft.Extensions.Hosting; namespace CompServ.Worker; internal class ConsoleTitleUpdateService : BackgroundService { private const int UpdatePerSecond = 2; protected override async Task ExecuteAsync(CancellationToken stoppingToken) { var lastRIn = 0; var lastBIn = 0L; var lastBOut = 0L; var lastDt = DateTime.Now; while (stoppingToken.IsCancellationRequested == false) { await Task.Delay(1000 / UpdatePerSecond, stoppingToken); var rIn = StatusHolder.RequestIn; var rOut = StatusHolder.RequestOut; var bIn = StatusHolder.BytesIn; var bOut = StatusHolder.BytesOut; var dt = DateTime.Now; var rRun = rIn - rOut; var riSpeed = (rIn - lastRIn) / (dt - lastDt).TotalSeconds; var biSpeed = (bIn - lastBIn) / (dt - lastDt).TotalSeconds; var boSpeed = (bOut - lastBOut) / (dt - lastDt).TotalSeconds; Console.Title = $"XZSx{StatusHolder.Ratio} [{dt:dd HH:mm:ss.f}]" + $" ReqRIO:{rRun}/{rIn}/{rOut}" + $" ByteIO:{bIn:N0}/{bOut:N0}" + $" SpeedRiBiBo:{riSpeed:N1}/{biSpeed}/{boSpeed}"; lastRIn = rIn; lastBIn = bIn; lastBOut = bOut; lastDt = dt; } } }