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(); } } }