46 lines
1.0 KiB
C#
46 lines
1.0 KiB
C#
#if NETCOREAPP
|
|
using System;
|
|
using System.Timers;
|
|
using Cysharp.Threading.Tasks;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
namespace BITKit;
|
|
|
|
public class BITAppForNet
|
|
{
|
|
private static readonly Timer _timer = new();
|
|
|
|
private static readonly DateTime _startTime = DateTime.UtcNow;
|
|
|
|
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;
|
|
|
|
|
|
_timer.Elapsed += OnTick;
|
|
_timer.Interval = 16;
|
|
_timer.Start();
|
|
|
|
await BITApp.Start(name);
|
|
await BITBinary.Start();
|
|
}
|
|
|
|
private static void OnTick(object sender, ElapsedEventArgs e)
|
|
{
|
|
var time = (DateTime.UtcNow - _startTime).TotalSeconds;
|
|
BITApp.Time.TimeAsDouble = time;
|
|
BITApp.Time.ElapsedTime = (float) time;
|
|
}
|
|
|
|
public static UniTask DisposeAsync()
|
|
{
|
|
_timer.Stop();
|
|
_timer.Elapsed -= OnTick;
|
|
BITApp.Stop();
|
|
return UniTask.CompletedTask;
|
|
}
|
|
}
|
|
#endif |