Program.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Threading;
  5. using CommandLine;
  6. using NLog;
  7. namespace ET
  8. {
  9. internal static class Program
  10. {
  11. private static void Main(string[] args)
  12. {
  13. // 异步方法全部会回掉到主线程
  14. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  15. try
  16. {
  17. Game.EventSystem.Add(typeof(Game).Assembly);
  18. Game.EventSystem.Add(DllHelper.GetHotfixAssembly());
  19. MongoHelper.Init();
  20. // 命令行参数
  21. Options options = null;
  22. Parser.Default.ParseArguments<Options>(args)
  23. .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
  24. .WithParsed(o => { options = o; });
  25. Game.Options = options;
  26. LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Scene.Id:0000}";
  27. Log.Info($"server start........................ {Game.Scene.Id}");
  28. Game.EventSystem.Publish(new EventType.AppStart());
  29. while (true)
  30. {
  31. try
  32. {
  33. Thread.Sleep(1);
  34. ThreadSynchronizationContext.Instance.Update();
  35. Game.EventSystem.Update();
  36. }
  37. catch (Exception e)
  38. {
  39. Log.Error(e);
  40. }
  41. }
  42. }
  43. catch (Exception e)
  44. {
  45. Log.Error(e);
  46. }
  47. }
  48. }
  49. }