RAGECOOP-V/Server/Program.cs

71 lines
2.1 KiB
C#
Raw Normal View History

2021-07-07 13:36:25 +02:00
using System;
using System.Diagnostics;
2021-07-07 13:36:25 +02:00
using System.IO;
using System.Threading;
using System.Threading.Tasks;
2021-07-07 13:36:25 +02:00
namespace CoopServer
{
class Program
{
public static bool ReadyToStop = false;
2021-07-07 13:36:25 +02:00
static void Main(string[] args)
{
try
{
#if DEBUG
new Thread(async () =>
{
do
{
Console.Title = string.Format("GTAC:R [{0,5:P2}] [{1:F}MB]", await GetCpuUsageForProcess(), Process.GetCurrentProcess().PrivateMemorySize64 * 0.000001);
Thread.Sleep(500);
} while (true);
}).Start();
#else
Console.Title = "GTACOOP:R";
#endif
2021-07-07 13:36:25 +02:00
if (File.Exists("log.txt"))
{
File.WriteAllText("log.txt", string.Empty);
}
Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
{
if (e.SpecialKey == ConsoleSpecialKey.ControlC)
{
e.Cancel = true;
ReadyToStop = true;
}
};
2021-07-07 13:36:25 +02:00
_ = new Server();
}
catch (Exception e)
{
Logging.Error(e.ToString());
Console.ReadLine();
}
}
#if DEBUG
private static async Task<double> GetCpuUsageForProcess()
{
DateTime startTime = DateTime.UtcNow;
TimeSpan startCpuUsage = Process.GetCurrentProcess().TotalProcessorTime;
await Task.Delay(500);
DateTime endTime = DateTime.UtcNow;
TimeSpan endCpuUsage = Process.GetCurrentProcess().TotalProcessorTime;
double cpuUsedMs = (endCpuUsage - startCpuUsage).TotalMilliseconds;
double totalMsPassed = (endTime - startTime).TotalMilliseconds;
double cpuUsageTotal = cpuUsedMs / (Environment.ProcessorCount * totalMsPassed);
return cpuUsageTotal * 100;
}
#endif
2021-07-07 13:36:25 +02:00
}
}