/// <summary> /// 每秒触发事件(下载速度计算) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _timer_Elapsed(object sender, ElapsedEventArgs e) { DownloadSpeedChangedArg arg = new DownloadSpeedChangedArg { SizePerSec = _downloadSizePerSec }; if (_downloadSizePerSec > 1048576) { arg.SpeedUnit = "MB/s"; arg.SpeedValue = Math.Round((decimal)_downloadSizePerSec / (decimal)1048576, 2); DownloadSpeedChanged?.Invoke(this, arg); } else if (_downloadSizePerSec > 1024) { arg.SpeedUnit = "KB/s"; arg.SpeedValue = Math.Round((decimal)_downloadSizePerSec / (decimal)1024, 2); DownloadSpeedChanged?.Invoke(this, arg); } else { arg.SpeedUnit = "B/s"; arg.SpeedValue = _downloadSizePerSec; DownloadSpeedChanged?.Invoke(this, arg); } _downloadSizePerSec = 0; }
private void _timer_Elapsed(object sender, ElapsedEventArgs e) { DownloadSpeedChangedArg arg = new DownloadSpeedChangedArg(); if (_downloadSizePerSec > 1048576) { arg.SpeedUnit = "MB/s"; arg.SpeedValue = _downloadSizePerSec / 1048576; DownloadSpeedChanged?.Invoke(this, arg); } else if (_downloadSizePerSec > 1024) { arg.SpeedUnit = "KB/s"; arg.SpeedValue = _downloadSizePerSec / 1024; DownloadSpeedChanged?.Invoke(this, arg); } else { arg.SpeedUnit = "B/s"; arg.SpeedValue = _downloadSizePerSec; DownloadSpeedChanged?.Invoke(this, arg); } _downloadSizePerSec = 0; }