Program.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Reflection;
  3. using System.Windows.Forms;
  4. namespace OTSMeasureApp
  5. {
  6. static class Program
  7. {
  8. /// <summary>
  9. /// 应用程序的主入口点。
  10. /// </summary>
  11. static Program()
  12. {
  13. string privatepath = "System;Common;DevExpress;FEIAutoScript;SQLiteDll;OxfordExtender;OTSCPPDll;OpenCvSharp;CefSharp";
  14. AppDomain.CurrentDomain.SetData("PRIVATE_BINPATH", privatepath);
  15. AppDomain.CurrentDomain.SetData("BINPATH_PROBE_ONLY", privatepath);
  16. var m = typeof(AppDomainSetup).GetMethod("UpdateContextProperty", BindingFlags.NonPublic | BindingFlags.Static);
  17. var funsion = typeof(AppDomain).GetMethod("GetFusionContext", BindingFlags.NonPublic | BindingFlags.Instance);
  18. m.Invoke(null, new object[] { funsion.Invoke(AppDomain.CurrentDomain, null), "PRIVATE_BINPATH", privatepath });
  19. }
  20. [STAThread]
  21. static void Main()
  22. {
  23. if (!System.Diagnostics.Debugger.IsAttached)
  24. {
  25. //判断是否有授权
  26. var reg = new CRegistration();
  27. if (!reg.RegistrationVerification())
  28. {
  29. MessageBox.Show("Error: missing authorization");
  30. System.Environment.Exit(0);
  31. return;
  32. }
  33. }
  34. //--------------------------只运行一个测量程序--------------------------------
  35. bool flag = false;
  36. System.Threading.Mutex mutex = new System.Threading.Mutex(true, "OTSIncAMeasureApp", out flag);
  37. //第一个参数:true--给调用线程赋予互斥体的初始所属权
  38. //第一个参数:互斥体的名称
  39. //第三个参数:返回值,如果调用线程已被授予互斥体的初始所属权,则返回true
  40. if (!flag)
  41. {
  42. MessageBox.Show("Only one measurement program can be run!", "please confirm", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  43. Environment.Exit(0);//退出程序
  44. }
  45. //AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
  46. Application.EnableVisualStyles();
  47. Application.SetCompatibleTextRenderingDefault(false);
  48. Application.Run(new OTSIncAMeasureAppForm());
  49. }
  50. }
  51. }