Program.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. if (!System.Diagnostics.Debugger.IsAttached)
  14. {
  15. //判断是否有授权
  16. var reg = new CRegistration();
  17. if (!reg.RegistrationVerification())
  18. {
  19. MessageBox.Show("Error: missing authorization");
  20. System.Environment.Exit(0);
  21. return;
  22. }
  23. }
  24. //--------------------------只运行一个测量程序--------------------------------
  25. bool flag = false;
  26. System.Threading.Mutex mutex = new System.Threading.Mutex(true, "OTSIncAMeasureApp", out flag);
  27. //第一个参数:true--给调用线程赋予互斥体的初始所属权
  28. //第一个参数:互斥体的名称
  29. //第三个参数:返回值,如果调用线程已被授予互斥体的初始所属权,则返回true
  30. if (!flag)
  31. {
  32. MessageBox.Show("Only one measurement program can be run!", "please confirm", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  33. Environment.Exit(0);//退出程序
  34. }
  35. Application.EnableVisualStyles();
  36. Application.SetCompatibleTextRenderingDefault(false);
  37. Application.Run(new OTSIncAMeasureAppForm());
  38. }
  39. }
  40. }