diff --git a/Netch/Forms/MainForm.Control.cs b/Netch/Forms/MainForm.Control.cs index f64b0bba..2f47f202 100644 --- a/Netch/Forms/MainForm.Control.cs +++ b/Netch/Forms/MainForm.Control.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Numerics; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -93,11 +94,11 @@ namespace Netch.Forms } } - public void OnBandwidthUpdated(long download) + public void OnBandwidthUpdated(ulong download) { if (InvokeRequired) { - BeginInvoke(new Action(OnBandwidthUpdated), download); + BeginInvoke(new Action(OnBandwidthUpdated), download); return; } @@ -117,44 +118,14 @@ namespace Netch.Forms } } - public void OnBandwidthUpdated(long upload, long download) - { - if (InvokeRequired) - { - BeginInvoke(new Action(OnBandwidthUpdated), upload, download); - return; - } - - try - { - if (upload < 1 || download < 1) - { - return; - } - - UsedBandwidthLabel.Text = - $"{i18N.Translate("Used", ": ")}{Bandwidth.Compute(upload + download)}"; - UploadSpeedLabel.Text = $"↑: {Bandwidth.Compute(upload - LastUploadBandwidth)}/s"; - DownloadSpeedLabel.Text = $"↓: {Bandwidth.Compute(download - LastDownloadBandwidth)}/s"; - - LastUploadBandwidth = upload; - LastDownloadBandwidth = download; - Refresh(); - } - catch - { - // ignored - } - } - /// /// 上一次上传的流量 /// - public long LastUploadBandwidth; + public ulong LastUploadBandwidth; /// /// 上一次下载的流量 /// - public long LastDownloadBandwidth; + public ulong LastDownloadBandwidth; } } \ No newline at end of file diff --git a/Netch/Utils/Bandwidth.cs b/Netch/Utils/Bandwidth.cs index 6c809080..20bc8d1e 100644 --- a/Netch/Utils/Bandwidth.cs +++ b/Netch/Utils/Bandwidth.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Numerics; using System.Threading.Tasks; using Microsoft.Diagnostics.Tracing.Parsers; using Microsoft.Diagnostics.Tracing.Session; @@ -13,7 +14,7 @@ namespace Netch.Utils { public static class Bandwidth { - public static int received; + public static ulong received; public static TraceEventSession tSession; /// @@ -21,7 +22,7 @@ namespace Netch.Utils /// /// 流量 /// 带单位的流量字符串 - public static string Compute(long size) + public static string Compute(ulong size) { var mStrSize = @"0"; const double step = 1024.00; @@ -96,7 +97,7 @@ namespace Netch.Utils if (processList.Contains(data.ProcessID)) { lock (counterLock) - received += data.size; + received += ulong.Parse(data.size.ToString()); // Debug.WriteLine($"TcpIpRecv: {ToByteSize(data.size)}"); } @@ -106,7 +107,7 @@ namespace Netch.Utils if (processList.Contains(data.ProcessID)) { lock (counterLock) - received += data.size; + received += ulong.Parse(data.size.ToString()); // Debug.WriteLine($"UdpIpRecv: {ToByteSize(data.size)}"); }