private void Form1_Load(object sender, System.EventArgs e) { #if DEBUG this.mi_ViewLog.Visible = true; this.menuItem_Split2.Visible = true; #else this.mi_ViewLog.Visible = false; this.menuItem_Split2.Visible = false; #endif dp = new DataProcess.DataProcess(); //文件修改时间 try { DateTime dt = System.IO.File.GetLastWriteTime("Monitor.exe"); lb_Version.Text = "版本:" + dt.ToString("yyyy-MM-dd"); } catch { } bRun = true; bInit = false; System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadCheckTime)); th.Start(); }
private void ThreadCheckTime() { SetText("正在启动程序.......", lb_state); if (dp.Start()) { SetText("运行中...", lb_state); } else { SetText("开始失败。", lb_state); return; } uint dt1 = LogInfo.Win32API.GetTickCount(); while (bRun) { System.Threading.Thread.Sleep(500); try { uint dt2 = LogInfo.Win32API.GetTickCount(); uint ts = dt2 - dt1; ts = ts / 1000; if (ts > 3600) { int curHour = DateTime.Now.Hour; if (curHour == LogInfo.Constant.SysRebootTime) { if (dp != null) { dp.Stop(); } System.Threading.Thread.Sleep(10000); System.Diagnostics.Process.Start(Application.StartupPath + "\\Monitor.exe"); dp = null; break; } } uint Seconds = ts % 60; ts = (ts - Seconds) / 60; uint Minutes = ts % 60; ts = (ts - Minutes) / 60; uint Hours = ts % 24; uint Days = (ts - Hours) / 24; string msg = "运行时间:" + Days.ToString() + "天" + Hours.ToString() + "小时" + Minutes.ToString() + "分" + Seconds.ToString() + "秒"; SetText(msg, lbRunTime); } catch (Exception ee) { MessageBox.Show(ee.ToString()); } } if (bRun) { CloseWindow(); } }
private void Form1_Closing(object sender, CancelEventArgs e) { bRun = false; if (dp != null) { dp.Stop(); dp = null; } }
private void menuItem_Exit_Click(object sender, System.EventArgs e) { bRun = false; if (dp != null) { dp.Stop(); dp = null; } Application.Exit(); }