Refactor show Bandwidth

This commit is contained in:
ChsBuffer
2021-01-05 17:53:16 +08:00
parent 1c974d295b
commit fe69c5a67b
3 changed files with 15 additions and 15 deletions

View File

@@ -42,7 +42,7 @@ namespace Netch.Forms
if (await MainController.Start(server, mode))
{
State = State.Started;
_ = Task.Run(() => { Bandwidth.NetTraffic(server, mode); });
_ = Task.Run(() => { Bandwidth.NetTraffic(); });
// 如果勾选启动后最小化
if (Global.Settings.MinimizeWhenStarted)
{

View File

@@ -70,25 +70,13 @@ namespace Netch.Forms
ProfileGroupBox.Enabled = true;
//Socks5
Boolean s5BwFlag = true;
if (MainController.Server is Socks5)
{
Socks5 SocksServer = (Socks5) MainController.Server;
if (!SocksServer.Auth()) s5BwFlag = false;
}
//Socks5无身份验证且为网页代理模式时无法统计流量不显示流量状态栏Socks5有身份验证时将统计V2ray的流量
if (s5BwFlag || Models.ModeExtension.TestNatRequired(MainController.Mode))
UsedBandwidthLabel.Visible /*= UploadSpeedLabel.Visible*/ = DownloadSpeedLabel.Visible = Global.Flags.IsWindows10Upper;
break;
case State.Stopping:
ControlButton.Enabled = false;
ControlButton.Text = "...";
ProfileGroupBox.Enabled = false;
UsedBandwidthLabel.Visible /*= UploadSpeedLabel.Visible*/ = DownloadSpeedLabel.Visible = false;
BandwidthState(false);
NatTypeStatusText();
break;
case State.Stopped:
@@ -110,6 +98,11 @@ namespace Netch.Forms
}
}
public void BandwidthState(bool state)
{
UsedBandwidthLabel.Visible /*= UploadSpeedLabel.Visible*/ = DownloadSpeedLabel.Visible = state;
}
public void NatTypeStatusText(string text = "", string country = "")
{
if (InvokeRequired)

View File

@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Microsoft.Diagnostics.Tracing.Parsers;
using Microsoft.Diagnostics.Tracing.Session;
using Netch.Controllers;
using Netch.Forms;
using Netch.Models;
using Netch.Servers.Shadowsocks;
using Netch.Servers.Socks5;
@@ -54,7 +55,7 @@ namespace Netch.Utils
/// <summary>
/// 根据程序名统计流量
/// </summary>
public static void NetTraffic(in Server server, in Mode mode)
public static void NetTraffic()
{
if (!Global.Flags.IsWindows10Upper)
return;
@@ -101,6 +102,12 @@ namespace Netch.Utils
instances.Select(instance => $"({instance.Id})" + instance.ProcessName).ToArray()));
received = 0;
if (!instances.Any())
return;
Global.MainForm.BandwidthState(true);
Task.Run(() =>
{
tSession = new TraceEventSession("KernelAndClrEventsSession");