Program.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. //static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
  51. //{
  52. // string dllname = args.Name.Split(',')[0];
  53. // string path;
  54. // if (dllname.Contains("OINA"))
  55. // {
  56. // if (dllname.Contains("resource"))
  57. // {
  58. // return null;
  59. // }
  60. // if (dllname.Contains("XmlSerialize"))
  61. // {
  62. // return null;
  63. // }
  64. // path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"OxfordExtender");
  65. //}
  66. // else if (dllname.Contains("resource"))
  67. // {
  68. // return null;
  69. // }
  70. // else
  71. // {
  72. // path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"OTSCPPDll");
  73. // }
  74. // path = System.IO.Path.Combine(path, dllname);
  75. // path = String.Format(@"{0}.dll", path);
  76. // //if (path.Contains("CefSharp")) return null;
  77. // return System.Reflection.Assembly.LoadFrom(path);
  78. //}
  79. }
  80. }