星火批注
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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