Program.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.Windows.Forms;
  6. namespace HOZProject
  7. {
  8. static class Program
  9. {
  10. /// <summary>
  11. /// 应用程序的主入口点。
  12. /// </summary>
  13. [STAThread]
  14. static void Main()
  15. {
  16. Application.EnableVisualStyles();
  17. Application.SetCompatibleTextRenderingDefault(false);
  18. //Application.Run(new FormUCMain());
  19. //Application.Run(new FormHOZMain());
  20. //Application.Run(new FormMeasureTest());
  21. //Application.Run(new FormUnitControl());
  22. bool createdNew;//返回是否赋予了使用线程的互斥体初始所属权
  23. System.Threading.Mutex instance = new System.Threading.Mutex(true, "MutexName", out createdNew); //同步基元变量
  24. if (createdNew) //赋予了线程初始所属权,也就是首次使用互斥体
  25. {
  26. FormHOZMain mainForm = new FormHOZMain();
  27. Application.Run(mainForm);
  28. //Application.Run(new FormUnitControl());
  29. instance.ReleaseMutex();
  30. }
  31. else
  32. {
  33. MessageBox.Show("已经启动了一个程序,请先退出!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  34. Application.Exit();
  35. }
  36. }
  37. }
  38. }