static void Main() { IntPtr hwndBarcode = FindWindow(null, "2dscan"); if (hwndBarcode != IntPtr.Zero) //判断系统自带的二维程序是否在运行 { SendMessage(hwndBarcode, WM_DESTROY, 0, 0); //向窗口发消息让其退出运行 } try { if (!MutexHelper.IsApplicationOnRun()) { Application.Run(new Main()); Application.Exit(); } else { MessageBox.Show("异常错误,请重启设备!");//如果该程序已经运行则返回,避免程序重复运行 return; } } catch (Exception e) { MessageBox.Show(e.Message, "程序异常"); } }
static void Main() { try { BaseVariable.InitXmlVar();//初始化基础变量 if (!File.Exists(BaseVariable.XmlFilePath)) { throw new Exception("Config.xml配置文件不存在,请检查"); } XmlHelper xml = new XmlHelper(); BaseVariable.RequestURL = xml.SelectValue("/Root/Server/APIURL"); string modelVaild = xml.SelectValue("/Root/Sys/ModelVaild"); if (modelVaild.Trim().Equals("1")) { string c = BaseVariable.APPRootPath + "config.dat"; if (!File.Exists(BaseVariable.XmlFilePath)) { throw new Exception("config.dat系统文件不存在,请检查"); } SystemIdentity info = SystemIdentity.GetFromFile(c); if (info.GetDeviceModel() != "CK3X") { throw new Exception("设备版本不兼容!!!"); } } string appName = Assembly.GetExecutingAssembly().GetName().Name; if (!MutexHelper.IsApplicationOnRun(appName)) { #region 创建快捷方式 Shortcut sc = new Shortcut(Assembly.GetExecutingAssembly(), "鸿泰集成防错系统"); if (!sc.IsExist()) { sc.Create(); } #endregion TaskBarHelper.ShowTaskBar(false); Application.Run(new FrmLogin()); Application.Exit(); } else { MessageBox.Show("系统正在运行!");//如果该程序已经运行则返回,避免程序重复运行 Application.Exit(); return; } } catch (Exception e) { MessageBox.Show(e.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); } finally { TaskBarHelper.ShowTaskBar(true); } }