From 68880f0c9be5fd3ef2840c64875cd22674e80b0f Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Sat, 29 Aug 2020 22:14:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=20NAT=20=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E8=AE=B0=E5=BD=95=E6=98=AF=E5=90=A6=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=AE=8C=E6=AF=95,=E6=94=B9=E8=BF=9B=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E6=B5=8B=E8=AF=95NAT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Netch/Controllers/MainController.cs | 35 +++++++++++++---------------- Netch/Forms/MainForm.cs | 5 ++--- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index 9412f399..eae40dfb 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -205,20 +205,7 @@ namespace Netch.Controllers case 0: case 1: case 2: - _ = Task.Run(() => - { - Global.MainForm.NatTypeStatusText(i18N.Translate("Starting NatTester")); - // Thread.Sleep(1000); - var (nttResult, natType, localEnd, publicEnd) = pNTTController.Start(); - - if (nttResult) - { - var country = Utils.Utils.GetCityCode(publicEnd); - Global.MainForm.NatTypeStatusText(natType, country); - } - else - Global.MainForm.NatTypeStatusText(natType); - }); + NatTest(); break; } } @@ -240,19 +227,29 @@ namespace Netch.Controllers return result; } + public bool NttTested; + /// - /// 重测NAT + /// 测试 NAT /// - public void RetryNatTest() + public void NatTest() { - _ = Task.Run(() => + NttTested = false; + Task.Run(() => { Global.MainForm.NatTypeStatusText(i18N.Translate("Starting NatTester")); // Thread.Sleep(1000); var (nttResult, natType, localEnd, publicEnd) = pNTTController.Start(); - var country = Utils.Utils.GetCityCode(publicEnd); - if (nttResult) Global.MainForm.NatTypeStatusText(natType, country); + if (nttResult) + { + var country = Utils.Utils.GetCityCode(publicEnd); + Global.MainForm.NatTypeStatusText(natType, country); + } + else + Global.MainForm.NatTypeStatusText(natType); + + NttTested = true; }); } diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs index 1c993919..1a05d663 100644 --- a/Netch/Forms/MainForm.cs +++ b/Netch/Forms/MainForm.cs @@ -444,10 +444,9 @@ namespace Netch.Forms private void NatTypeStatusLabel_Click(object sender, EventArgs e) { - //一个不太优雅的🔒 - if (_state == State.Started && NatTypeStatusLabel.ToString().Contains("[")) + if (_state == State.Started && _mainController.NttTested) { - _mainController.RetryNatTest(); + _mainController.NatTest(); } } }