|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using Common.system;
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Diagnostics;
- using System.IO;
- using System.Threading;
- using System.Windows;
- using System.Windows.Threading;
-
- namespace XHWK.System
- {
- public partial class APP : Application
- {
- [STAThread]
- private static void Main()
- {
- // 定义Application对象作为整个应用程序入口
- Application app = new Application();
- //app.DispatcherUnhandledException += MyApp_DispatcherUnhandledException;
- // 方法一:调用Run方法 ,这种方式跟winform的调用一样
- MainWindow win = new MainWindow();
- app.Run(win);
- LogHelper.WriteInfoLog("启动项目");
- StopSameProcess();
- }
-
- private static void StopSameProcess()
- {
- Process current = Process.GetCurrentProcess();
- Process[] processList = Process.GetProcesses();
- foreach (Process process in processList)
- {
- if (process.ProcessName.ToUpper() == "XHSCHOOL")
- {
- if (process.Id != current.Id) //忽略当前进程
- {
- try
- {
- process.Kill(); //结束进程
- }
- catch (Exception)
- {
-
- }
- }
- }
- }
- }
-
- private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
- {
- LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
- MessageBox.Show("程序异常." + Environment.NewLine + e.Exception.Message);
- e.Handled = true;
- }
-
- #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
-
- /// <summary>
- /// 内存释放压缩
- /// </summary>
- /// <param name="e"></param>
- protected override void OnStartup(StartupEventArgs e)
- {
- //private LierdaCracker cracker = new LierdaCracker();
- //cracker.Cracker(5000);//间隔时间
- //base.OnStartup(e);
- new Thread(o =>
- {
- while (true)
- {
- try
- {
- //FreeMemoryHelper.SetDate();
- FreeMemoryHelper.ReallocateMemory();
- Thread.Sleep(20000);//暂定每20秒释放一次
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
- }
- }
- }).Start();
- }
-
- #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
- }
- }
|