From d88d1b2e0cdd8618e6bfad95bb3b619cb520d82f Mon Sep 17 00:00:00 2001 From: AmazingDM Date: Fri, 28 Aug 2020 14:55:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E9=87=8F=E7=BB=9F=E8=AE=A1=E6=94=B9?= =?UTF-8?q?=E4=B8=BAulong=20=E4=BF=AE=E5=A4=8D=E8=B6=85=E8=BF=872g?= =?UTF-8?q?=E7=88=86=E7=82=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Netch/Forms/MainForm.Control.cs | 39 +++++---------------------------- Netch/Utils/Bandwidth.cs | 9 ++++---- 2 files changed, 10 insertions(+), 38 deletions(-) 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)}"); }