BITKit/Src/Core/Applation/BITAppForNet.cs

46 lines
1.0 KiB
C#
Raw Normal View History

2023-08-23 01:59:26 +08:00
#if NETCOREAPP
2023-10-06 23:43:19 +08:00
using System;
2024-06-25 15:39:52 +08:00
using System.Timers;
2023-08-23 01:59:26 +08:00
using Cysharp.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace BITKit;
public class BITAppForNet
{
2025-01-12 11:13:19 +08:00
private static readonly Timer _timer = new();
2024-06-25 15:39:52 +08:00
2025-01-12 11:13:19 +08:00
private static readonly DateTime _startTime = DateTime.UtcNow;
2023-08-23 01:59:26 +08:00
public static async UniTask InitializeAsync(string name)
{
BIT4Log.OnLog += Console.WriteLine;
BIT4Log.OnWarning += Console.WriteLine;
BIT4Log.OnException += e => Console.WriteLine(e.ToString());
BIT4Log.OnNextLine += Console.WriteLine;
2024-06-25 15:39:52 +08:00
_timer.Elapsed += OnTick;
_timer.Interval = 16;
_timer.Start();
2023-08-23 01:59:26 +08:00
2023-10-06 23:43:19 +08:00
await BITApp.Start(name);
2023-08-23 01:59:26 +08:00
await BITBinary.Start();
}
2024-06-25 15:39:52 +08:00
private static void OnTick(object sender, ElapsedEventArgs e)
{
var time = (DateTime.UtcNow - _startTime).TotalSeconds;
BITApp.Time.TimeAsDouble = time;
BITApp.Time.ElapsedTime = (float) time;
}
2023-08-23 01:59:26 +08:00
public static UniTask DisposeAsync()
{
2024-06-25 15:39:52 +08:00
_timer.Stop();
_timer.Elapsed -= OnTick;
2023-08-23 01:59:26 +08:00
BITApp.Stop();
return UniTask.CompletedTask;
}
}
#endif