using System; using System.IO; using System.IO.Pipes; using System.Threading; using CommandLine; using GFGGame; using NLog; namespace ET { internal static class Program { private static void Main(string[] args) { var processId = Environment.ProcessId; Console.WriteLine("Process ID: " + processId); AppDomain.CurrentDomain.UnhandledException += (sender, e) => { Log.Error(e.ExceptionObject.ToString()); }; ETTask.ExceptionHandler += Log.Error; // 异步方法全部会回掉到主线程 SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance); try { // 命令行参数 Options options = null; Parser.Default.ParseArguments(args) .WithNotParsed(error => throw new Exception($"命令行格式错误!")) .WithParsed(o => { options = o; }); Options.Instance = options; Log.ILog = new NLogger(Game.Options.AppType.ToString()); //用于后台收集日志 LogExt.ILog = new NLogger("GFGLog"); LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}"; Game.EventSystem.Add(typeof(Game).Assembly); Game.EventSystem.Add(DllHelper.GetHotfixAssembly()); ProtobufHelper.Init(); MongoRegister.Init(); Log.Info($"server start........................ {Game.Scene.Id}"); Game.EventSystem.Publish(new EventType.AppStart()); AppDomain.CurrentDomain.ProcessExit += (sender, e) => { var isClose = new ParamHolder(false); if (options.AppType == AppType.Watcher) { Game.EventSystem.AppClose(isClose); while (!isClose.Value) { Thread.Sleep(1000); } } else { Game.EventSystem.AppClose(isClose); Thread.Sleep(3000); } }; while (true) { try { Thread.Sleep(1); Game.Update(); Game.LateUpdate(); Game.FrameFinish(); } catch (Exception e) { Log.Error(e); } } } catch (Exception e) { Log.Error(e); } } } }