Program.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. bool createdNew;//返回是否赋予了使用线程的互斥体初始所属权
  19. System.Threading.Mutex instance = new System.Threading.Mutex(true, "MutexName", out createdNew); //同步基元变量
  20. if (createdNew) //赋予了线程初始所属权,也就是首次使用互斥体
  21. {
  22. FormHOZMain mainForm = new FormHOZMain();
  23. Application.Run(mainForm);
  24. instance.ReleaseMutex();
  25. }
  26. else
  27. {
  28. MessageBox.Show("已经启动了一个程序,请先退出!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  29. Application.Exit();
  30. }
  31. }
  32. }
  33. }