星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 4 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using Common.system;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Threading;
  11. namespace XHWK.WKTool
  12. {
  13. public partial class APP : Application
  14. {
  15. [STAThread]
  16. private static void Main()
  17. {
  18. // 定义Application对象作为整个应用程序入口
  19. Application app = new Application();
  20. //app.DispatcherUnhandledException += MyApp_DispatcherUnhandledException;
  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. }