static void Main(string[] args) { #region 处理来自参数的快速启动请求,跳过对OPCSERVER的三分钟等待 foreach (string arg in args) { if (arg.Contains("fast")) { waitMillionSecond = 1000; break; } } #endregion bool createNew; //try //{ //Console.WriteLine(Application.ProductName); using (System.Threading.Mutex m = new System.Threading.Mutex(true, "Global\\" + Application.ProductName, out createNew)) { if (createNew) { IniFile ini = new IniFile(AppDomain.CurrentDomain.BaseDirectory + "MicroDAQ.ini"); DatabaseManager = new DatabaseManager(ini.GetValue("Database", "Address"), ini.GetValue("Database", "Port"), ini.GetValue("Database", "Database"), ini.GetValue("Database", "Username"), ini.GetValue("Database", "Password")); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form MainForm = null; while (!BeQuit) try { MainForm = new MainForm(); //frmMain = new TestAlarm(); Application.Run(MainForm); } catch (Exception ex) { Console.WriteLine("OH. NO!" + ex.ToString()); } finally { if (MainForm != null) MainForm.Dispose(); } Environment.Exit(Environment.ExitCode); } else { MessageBox.Show("程序已经在运行,无法再次启动。", "已启动", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } //} //catch //{ // MessageBox.Show("Only one instance of this application is allowed!"); //} }
private void Form2_Load(object sender, EventArgs e) { ni.Icon = this.Icon; ni.Text = this.Text; bool autoStart = false; ; try { IniFile ini = new IniFile(AppDomain.CurrentDomain.BaseDirectory + "MicroDAQ.ini"); this.Text = ini.GetValue("General", "Title"); this.tsslProject.Text = "项目代码:" + ini.GetValue("General", "ProjetCode"); this.tsslVersion.Text = "接口版本:" + ini.GetValue("General", "VersionCode"); autoStart = bool.Parse(ini.GetValue("AutoRun", "AutoStart")); Duty = ini.GetValue("General", "Duty"); plcCount = int.Parse(ini.GetValue("PLCConfig", "Amount")); plcConnection = new string[plcCount]; meters = new int[plcCount]; dataItems = new int[plcCount]; for (int i = 0; i < plcCount; i++) plcConnection[i] = ini.GetValue(string.Format("PLC{0}", i), "Connection"); } catch { } finally { if (autoStart) btnStart_Click(null, null); } ni.Text = this.Text; }