流量统计改为ulong 修复超过2g爆炸的问题

This commit is contained in:
AmazingDM
2020-08-28 14:55:04 +08:00
parent a4081b1a7f
commit d88d1b2e0c
2 changed files with 10 additions and 38 deletions

View File

@@ -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<long>(OnBandwidthUpdated), download);
BeginInvoke(new Action<ulong>(OnBandwidthUpdated), download);
return;
}
@@ -117,44 +118,14 @@ namespace Netch.Forms
}
}
public void OnBandwidthUpdated(long upload, long download)
{
if (InvokeRequired)
{
BeginInvoke(new Action<long, long>(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
}
}
/// <summary>
/// 上一次上传的流量
/// </summary>
public long LastUploadBandwidth;
public ulong LastUploadBandwidth;
/// <summary>
/// 上一次下载的流量
/// </summary>
public long LastDownloadBandwidth;
public ulong LastDownloadBandwidth;
}
}

View File

@@ -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;
/// <summary>
@@ -21,7 +22,7 @@ namespace Netch.Utils
/// </summary>
/// <param name="bandwidth">流量</param>
/// <returns>带单位的流量字符串</returns>
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)}");
}