星火批注
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

APP.cs 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using Common.system;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Security.Principal;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Threading;
  14. using TStudyDigitalPen.HID;
  15. namespace XHPZ.Desktop
  16. {
  17. public partial class APP : Application
  18. {
  19. #region 全局变量
  20. /// <summary>
  21. /// 是否输出测试记录日志
  22. /// </summary>
  23. public static bool IsOutputInfoLog = FileToolsCommon.GetConfigValue("IsOutputInfoLog") != "0";
  24. /// <summary>
  25. /// 后台线程帮助类
  26. /// </summary>
  27. public static BackgroundWorkerHelper BackgroundWorkerHelper => BackgroundWorkerHelper.GetInstance();
  28. #region 点阵笔
  29. /// <summary>
  30. /// 点阵笔
  31. /// </summary>
  32. public static DigitalPenHID digitalPen;
  33. /// <summary>
  34. /// 笔序号
  35. /// </summary>
  36. public static string PenSerial;
  37. /// <summary>
  38. /// 笔状态,是否已连接
  39. /// </summary>
  40. public static bool PenStatus = false;
  41. /// <summary>
  42. /// 手写板状态,是否已连接
  43. /// </summary>
  44. public static bool BoardStatus = false;
  45. #endregion
  46. #region 腾千里手写笔
  47. /// <summary>
  48. /// 腾千里手写笔事件
  49. /// </summary>
  50. public static PenEvents TQLPenevents;
  51. /// <summary>
  52. /// 腾千里手写笔是否已连接
  53. /// </summary>
  54. public static bool TQLPenStatus = false;
  55. #endregion
  56. #region 页面
  57. ///// <summary>
  58. ///// 批注
  59. ///// </summary>
  60. public static PracticeWindow W_PracticeWindow = null;
  61. #endregion
  62. #endregion
  63. [STAThread]
  64. private static void Main()
  65. {
  66. StopSameProcess();
  67. try
  68. {
  69. #region 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  70. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  71. WindowsPrincipal principal = new WindowsPrincipal(identity);
  72. //判断当前登录用户是否为管理员
  73. //if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  74. //{
  75. // //如果是管理员,则直接运行
  76. // W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
  77. // // 定义Application对象作为整个应用程序入口
  78. // Application app = new Application();
  79. // app.Run(W_CreateAMicroLessonWindow);
  80. // //Application.Run(W_CreateAMicroLessonWindow);
  81. //}
  82. //else
  83. //{
  84. // //创建启动对象
  85. // System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  86. // {
  87. // UseShellExecute = true,
  88. // WorkingDirectory = Environment.CurrentDirectory,
  89. // FileName = Assembly.GetExecutingAssembly().Location,
  90. // //设置启动动作,确保以管理员身份运行
  91. // Verb = "runas"
  92. // };
  93. // try
  94. // {
  95. // System.Diagnostics.Process.Start(startInfo);
  96. // }
  97. // catch
  98. // {
  99. // return;
  100. // }
  101. // //退出
  102. // //Current.Shutdown();
  103. // Environment.Exit(0);
  104. //}
  105. #endregion
  106. try
  107. {
  108. if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "temp"))//清除临时文件
  109. {
  110. Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "temp", true);
  111. }
  112. }
  113. catch (Exception)
  114. {
  115. }
  116. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  117. {
  118. //如果是管理员,则直接运行
  119. MainWindow mainWindow = new MainWindow();
  120. // 定义Application对象作为整个应用程序入口
  121. Application app = new Application();
  122. app.Run(mainWindow);
  123. }
  124. else
  125. {
  126. //创建启动对象
  127. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  128. {
  129. UseShellExecute = true,
  130. WorkingDirectory = Environment.CurrentDirectory,
  131. FileName = Assembly.GetExecutingAssembly().Location,
  132. //设置启动动作,确保以管理员身份运行
  133. Verb = "runas"
  134. };
  135. try
  136. {
  137. System.Diagnostics.Process.Start(startInfo);
  138. }
  139. catch
  140. {
  141. return;
  142. }
  143. //退出
  144. //Current.Shutdown();
  145. Environment.Exit(0);
  146. }
  147. }
  148. catch (Exception ex)
  149. {
  150. string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  151. LogHelper.WriteErrLog(ErrMessage, ex);
  152. }
  153. }
  154. #region 杀死已存在的进程
  155. /// <summary>
  156. /// 结束已运行的程序
  157. /// </summary>
  158. private static void StopSameProcess()
  159. {
  160. Process current = Process.GetCurrentProcess();
  161. Process[] processList = Process.GetProcesses();
  162. foreach (Process process in processList)
  163. {
  164. if (process.ProcessName.ToUpper() == "星火批注")
  165. {
  166. if (process.Id != current.Id) //忽略当前进程
  167. {
  168. try
  169. {
  170. process.Kill(); //结束进程
  171. }
  172. catch (Exception)
  173. {
  174. }
  175. }
  176. }
  177. }
  178. }
  179. /// <summary>
  180. /// 杀死正在运行的ffmpeg
  181. /// </summary>
  182. public static void Killffmpeg()
  183. {
  184. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  185. foreach (Process KillProcess in KillProcessArray)
  186. {
  187. KillProcess.Kill();
  188. }
  189. }
  190. #endregion
  191. /// <summary>
  192. /// 错误处理
  193. /// </summary>
  194. /// <param name="sender"></param>
  195. /// <param name="e"></param>
  196. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  197. {
  198. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  199. //MessageWindow.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  200. e.Handled = true;
  201. }
  202. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  203. /// <summary>
  204. /// 内存释放压缩
  205. /// </summary>
  206. /// <param name="e"></param>
  207. protected override void OnStartup(StartupEventArgs e)
  208. {
  209. //private LierdaCracker cracker = new LierdaCracker();
  210. //cracker.Cracker(5000);//间隔时间
  211. //base.OnStartup(e);
  212. new Thread(o =>
  213. {
  214. while (true)
  215. {
  216. try
  217. {
  218. //FreeMemoryHelper.SetDate();
  219. FreeMemoryHelper.ReallocateMemory();
  220. Thread.Sleep(20000);//暂定每20秒释放一次
  221. }
  222. catch (Exception ex)
  223. {
  224. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  225. }
  226. }
  227. }).Start();
  228. }
  229. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  230. }
  231. }