Program.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using EEMSCenter.Hubs;
  2. using Microsoft.AspNetCore.Builder;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using System.Windows;
  5. namespace EEMSCenter;
  6. internal class Program
  7. {
  8. public static WebApplication? WebApplication { get; private set; }
  9. static void Main(string[] args)
  10. {
  11. Mutex mutex = new(true, "7E862400-8020-BE75-5266-B2C4BEB54075", out bool flag);
  12. if (!flag)
  13. return;
  14. AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
  15. TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
  16. WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
  17. builder.Services.AddSignalR(
  18. options =>
  19. {
  20. options.EnableDetailedErrors = true;
  21. options.MaximumReceiveMessageSize = 262144;//256k
  22. //options.ClientTimeoutInterval = TimeSpan.FromSeconds(5);
  23. //options.KeepAliveInterval = TimeSpan.FromSeconds(10);
  24. //options.MaximumParallelInvocationsPerClient = 5;
  25. });
  26. //Host Service
  27. builder.Services.AddHostedService<HostLifetime>();
  28. WebApplication = builder.Build();
  29. WebApplication.MapHub<UIHub>("/UIHub");
  30. WebApplication.MapHub<ClientsHub>("/ClientHub");
  31. WebApplication.RunAsync($"http://127.0.0.1:50054").Wait();
  32. }
  33. private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  34. {
  35. string? s = e.ExceptionObject?.ToString();
  36. MessageBox.Show(s is null ? "Unknow UnhandledException" : s);
  37. }
  38. private static void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
  39. {
  40. //_expLog.Fatal(e.Exception!.ToString()!);
  41. }
  42. }