/// <summary> /// 启动流量监测 /// </summary> /// <param name="interval"></param> /// <returns></returns> public bool Start(int interval = 1000) { if (Init() && !IsStart) { DataCounterInterval = interval; IsStart = true; Task.Factory.StartNew(() => { while (IsStart) { DataMonitorEvent?.Invoke(this); try { _UploadDataCount += _UploadData; _UploadData = 0; foreach (var uc in UploadCounter) { _UploadData += (int)uc?.NextValue(); } _DownloadDataCount += _DownloadData; _DownloadData = 0; foreach (var dc in DownloadCounter) { _DownloadData += (int)dc?.NextValue(); } } catch (Exception e) { } Thread.Sleep(DataCounterInterval); } }); return(true); } return(false); }
public virtual void OnMonitorEvent(string monitorTypeName, MonitorId monitorId, string currentStateName, string eventName, bool isProcessing) { MonitorEvent?.Invoke(monitorTypeName, monitorId, currentStateName, eventName, isProcessing); }