1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-13 08:38:19 -05:00

Added AsyncStatus class to keep track of the timing of each update on servers

This commit is contained in:
RaidMax
2017-05-28 15:47:21 -05:00
parent ac7908de91
commit 28fcc7b922
12 changed files with 111 additions and 41 deletions

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SharedLibrary
{
public sealed class AsyncStatus
{
CancellationToken Token;
DateTime StartTime;
int TimesRun;
public double RunAverage { get; private set; }
public object Dependant { get; private set; }
public Task RequestedTask { get; private set; }
public AsyncStatus(object dependant)
{
Token = new CancellationToken();
StartTime = DateTime.Now;
Dependant = dependant;
// technically 0 but it's faster than checking for division by 0
TimesRun = 1;
}
public CancellationToken GetToken()
{
return Token;
}
public double ElapsedMillisecondsTime()
{
return (DateTime.Now - StartTime).TotalMilliseconds;
}
public void Update(Task T)
{
RequestedTask = T;
RequestedTask.Start();
if (TimesRun > 100)
TimesRun = 1;
RunAverage = RunAverage + ((DateTime.Now - StartTime).TotalMilliseconds - RunAverage) / TimesRun;
StartTime = DateTime.Now;
}
}
}