星火微课系统客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using Common.system;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.Specialized;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Threading;
  8. using System.Windows;
  9. using System.Windows.Threading;
  10. namespace XHWK.System
  11. {
  12. public partial class APP : Application
  13. {
  14. [STAThread]
  15. private static void Main()
  16. {
  17. // 定义Application对象作为整个应用程序入口
  18. Application app = new Application();
  19. //app.DispatcherUnhandledException += MyApp_DispatcherUnhandledException;
  20. // 方法一:调用Run方法 ,这种方式跟winform的调用一样
  21. MainWindow win = new MainWindow();
  22. app.Run(win);
  23. LogHelper.WriteInfoLog("启动项目");
  24. StopSameProcess();
  25. }
  26. private static void StopSameProcess()
  27. {
  28. Process current = Process.GetCurrentProcess();
  29. Process[] processList = Process.GetProcesses();
  30. foreach (Process process in processList)
  31. {
  32. if (process.ProcessName.ToUpper() == "XHSCHOOL")
  33. {
  34. if (process.Id != current.Id) //忽略当前进程
  35. {
  36. try
  37. {
  38. process.Kill(); //结束进程
  39. }
  40. catch (Exception)
  41. {
  42. }
  43. }
  44. }
  45. }
  46. }
  47. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  48. {
  49. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  50. MessageBox.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  51. e.Handled = true;
  52. }
  53. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  54. /// <summary>
  55. /// 内存释放压缩
  56. /// </summary>
  57. /// <param name="e"></param>
  58. protected override void OnStartup(StartupEventArgs e)
  59. {
  60. //private LierdaCracker cracker = new LierdaCracker();
  61. //cracker.Cracker(5000);//间隔时间
  62. //base.OnStartup(e);
  63. new Thread(o =>
  64. {
  65. while (true)
  66. {
  67. try
  68. {
  69. //FreeMemoryHelper.SetDate();
  70. FreeMemoryHelper.ReallocateMemory();
  71. Thread.Sleep(20000);//暂定每20秒释放一次
  72. }
  73. catch (Exception ex)
  74. {
  75. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  76. }
  77. }
  78. }).Start();
  79. }
  80. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  81. }
  82. }