星火批注
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. public static MainWindow W_mainWindow = null;
  58. ///// <summary>
  59. ///// 批注
  60. ///// </summary>
  61. public static PracticeWindow W_PracticeWindow = null;
  62. #endregion
  63. #endregion
  64. [STAThread]
  65. private static void Main()
  66. {
  67. StopSameProcess();
  68. try
  69. {
  70. #region 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  71. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  72. WindowsPrincipal principal = new WindowsPrincipal(identity);
  73. //判断当前登录用户是否为管理员
  74. //if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  75. //{
  76. // //如果是管理员,则直接运行
  77. // W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
  78. // // 定义Application对象作为整个应用程序入口
  79. // Application app = new Application();
  80. // app.Run(W_CreateAMicroLessonWindow);
  81. // //Application.Run(W_CreateAMicroLessonWindow);
  82. //}
  83. //else
  84. //{
  85. // //创建启动对象
  86. // System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  87. // {
  88. // UseShellExecute = true,
  89. // WorkingDirectory = Environment.CurrentDirectory,
  90. // FileName = Assembly.GetExecutingAssembly().Location,
  91. // //设置启动动作,确保以管理员身份运行
  92. // Verb = "runas"
  93. // };
  94. // try
  95. // {
  96. // System.Diagnostics.Process.Start(startInfo);
  97. // }
  98. // catch
  99. // {
  100. // return;
  101. // }
  102. // //退出
  103. // //Current.Shutdown();
  104. // Environment.Exit(0);
  105. //}
  106. #endregion
  107. try
  108. {
  109. if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "temp"))//清除临时文件
  110. {
  111. Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "temp", true);
  112. }
  113. }
  114. catch (Exception)
  115. {
  116. }
  117. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  118. {
  119. //如果是管理员,则直接运行
  120. W_mainWindow = new MainWindow();
  121. // 定义Application对象作为整个应用程序入口
  122. Application app = new Application();
  123. app.Run(W_mainWindow);
  124. }
  125. else
  126. {
  127. //创建启动对象
  128. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  129. {
  130. UseShellExecute = true,
  131. WorkingDirectory = Environment.CurrentDirectory,
  132. FileName = Assembly.GetExecutingAssembly().Location,
  133. //设置启动动作,确保以管理员身份运行
  134. Verb = "runas"
  135. };
  136. try
  137. {
  138. System.Diagnostics.Process.Start(startInfo);
  139. }
  140. catch
  141. {
  142. return;
  143. }
  144. //退出
  145. //Current.Shutdown();
  146. Environment.Exit(0);
  147. }
  148. }
  149. catch (Exception ex)
  150. {
  151. string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  152. LogHelper.WriteErrLog(ErrMessage, ex);
  153. }
  154. }
  155. #region 杀死已存在的进程
  156. /// <summary>
  157. /// 结束已运行的程序
  158. /// </summary>
  159. private static void StopSameProcess()
  160. {
  161. Process current = Process.GetCurrentProcess();
  162. Process[] processList = Process.GetProcesses();
  163. foreach (Process process in processList)
  164. {
  165. if (process.ProcessName.ToUpper() == "星火批注")
  166. {
  167. if (process.Id != current.Id) //忽略当前进程
  168. {
  169. try
  170. {
  171. process.Kill(); //结束进程
  172. }
  173. catch (Exception)
  174. {
  175. }
  176. }
  177. }
  178. }
  179. }
  180. /// <summary>
  181. /// 杀死正在运行的ffmpeg
  182. /// </summary>
  183. public static void Killffmpeg()
  184. {
  185. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  186. foreach (Process KillProcess in KillProcessArray)
  187. {
  188. KillProcess.Kill();
  189. }
  190. }
  191. #endregion
  192. /// <summary>
  193. /// 错误处理
  194. /// </summary>
  195. /// <param name="sender"></param>
  196. /// <param name="e"></param>
  197. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  198. {
  199. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  200. //MessageWindow.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  201. e.Handled = true;
  202. }
  203. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  204. /// <summary>
  205. /// 内存释放压缩
  206. /// </summary>
  207. /// <param name="e"></param>
  208. protected override void OnStartup(StartupEventArgs e)
  209. {
  210. //private LierdaCracker cracker = new LierdaCracker();
  211. //cracker.Cracker(5000);//间隔时间
  212. //base.OnStartup(e);
  213. new Thread(o =>
  214. {
  215. while (true)
  216. {
  217. try
  218. {
  219. //FreeMemoryHelper.SetDate();
  220. FreeMemoryHelper.ReallocateMemory();
  221. Thread.Sleep(20000);//暂定每20秒释放一次
  222. }
  223. catch (Exception ex)
  224. {
  225. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  226. }
  227. }
  228. }).Start();
  229. }
  230. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  231. }
  232. }