星火批注
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.

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