/// <summary> /// 获取本地数据,包括当天使用的流量大小,提醒次数 /// </summary> private void GetDataFromLocal() { theDayFlow = Histroy.GetTheDayFlow(DateTime.Now); remindTime = new short[] { Properties.Settings.Default.RemindALL, Properties.Settings.Default.RemindUP }; }
/// <summary> /// 关闭监控 /// </summary> public void Close() { MainTimer.Dispose(); //Remind.GetRemind().Stop(); for (int i = 0; i < CaptureDeviceList.Instance.Count; i++) { var device = CaptureDeviceList.Instance[i]; device.StopCapture(); } Histroy.Write(); }
/* ------------------ Function ~ ------------------ */ /// <summary> /// 初始化。 /// </summary> private void Initialise() { // 获取本机IP地址 hostIP = getHostIPAddress(); // 新建线程监控。 /* * BackgroundWorker 类允许您在单独的专用线程上运行操作。 *耗时的操作(如下载和数据库事务)在长时间运行时可能会导致用户界面 (UI) 似乎处于停止响应状态。 *如果您需要能进行响应的用户界面,而且面临与这类操作相关的长时间延迟,则可以使用 BackgroundWorker 类方便地解决问题。 *若要在后台执行耗时的操作,请创建一个 BackgroundWorker ,侦听那些报告操作进度并在操作完成时发出信号的事件。 *可以通过编程方式创建 BackgroundWorker ,也可以将它从“工具箱”的“组件”选项卡中拖到窗体上。 *如果在 Windows 窗体设计器中创建 BackgroundWorker ,则它会出现在组件栏中,而且它的属性会显示在“属性”窗口中。 *若要设置后台操作,请为 DoWork 事件添加一个事件处理程序。在此事件处理程序中调用耗时的操作。 *若要启动该操作,请调用 RunWorkerAsync 。 */ backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); backgroundWorker1.DoWork += backgroundWorker_DoWork; backgroundWorker1.RunWorkerAsync(); // 创建数据库记录流量使用情况 try { Histroy.Init(); TheDayFlow = Histroy.GetTheDayFlow(DateTime.Now); } catch (Exception e) { System.Windows.MessageBox.Show(e.ToString()); } // 每秒处理数据 //到达时间的时候执行事件 MainTimer.Elapsed += ManageDataTimerEvent; MainTimer.Interval = 1000; //是否执行System.Timers.Timer.Elapsed事件 MainTimer.Enabled = true; // 每分钟写入流量信息。 /* * Timer FlowWriteTimer = new Timer(); * FlowWriteTimer.Elapsed += (a, b) => * { * Histroy.Write(); * }; * FlowWriteTimer.Interval = 60 * 1000; * FlowWriteTimer.Start(); */ }
private void CheckedExitPro() { foreach (DictionaryEntry de in processFlow) { Flow f = (Flow)de.Value; f.UpFlow += f.lastUp; f.DownFlow += f.lastDown; TheDayFlow[0] += f.lastUp; TheDayFlow[1] += f.lastDown; f.UpSpeed = f.lastUp; f.DownSpeed = f.lastDown; f.lastUp = 0; f.lastDown = 0; } foreach (Flow flow in ViewData) { // 查看进程是否运行 bool active = false; foreach (int pid in flow.pid) { if (ActivePIDs.IndexOf(pid) != -1) { active = true; } else { flow.pid.Remove(pid); } } if (!active) { System.Windows.Application.Current.Dispatcher.Invoke(new Action(delegate { ViewData.Remove(flow); Histroy.WriteDataByFlow(flow); })); } } }
/* ------------------ Function ~ ------------------ */ /// <summary> /// 初始化。 /// </summary> private void Initialise() { // 获取本机IP地址 hostIP = getHostIPAddress(); // 新建线程监控。 backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); backgroundWorker1.DoWork += backgroundWorker_DoWork; backgroundWorker1.RunWorkerAsync(); // 创建数据库记录流量使用情况 try { Histroy.Init(); TheDayFlow = Histroy.GetTheDayFlow(DateTime.Now); } catch (Exception e) { System.Windows.MessageBox.Show(e.ToString()); } // 每秒处理数据 MainTimer.Elapsed += ManageDataTimerEvent; MainTimer.Interval = 1000; MainTimer.Enabled = true; // 每分钟写入流量信息。 /* * Timer FlowWriteTimer = new Timer(); * FlowWriteTimer.Elapsed += (a, b) => * { * Histroy.Write(); * }; * FlowWriteTimer.Interval = 60 * 1000; * FlowWriteTimer.Start(); */ }