Program.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Windows.Forms;
  3. namespace OTSMeasureApp
  4. {
  5. static class Program
  6. {
  7. /// <summary>
  8. /// 应用程序的主入口点。
  9. /// </summary>
  10. [STAThread]
  11. static void Main()
  12. {
  13. //--------------------------只运行一个测量程序--------------------------------
  14. bool flag = false;
  15. System.Threading.Mutex mutex = new System.Threading.Mutex(true, "OTSIncAMeasureApp", out flag);
  16. //第一个参数:true--给调用线程赋予互斥体的初始所属权
  17. //第一个参数:互斥体的名称
  18. //第三个参数:返回值,如果调用线程已被授予互斥体的初始所属权,则返回true
  19. if (!flag)
  20. {
  21. MessageBox.Show("Only one measurement program can be run!", "please confirm", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  22. Environment.Exit(0);//退出程序
  23. }
  24. Application.EnableVisualStyles();
  25. Application.SetCompatibleTextRenderingDefault(false);
  26. Application.Run(new OTSIncAMeasureAppForm());
  27. }
  28. }
  29. }