mirror of
https://github.com/netchx/netch.git
synced 2026-03-14 17:43:18 +08:00
Revert NatTest Monitor lock
This commit is contained in:
@@ -36,7 +36,7 @@ namespace Netch.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
File.WriteAllText(Path.Combine(Global.NetchDir, $"logging\\{Name}.log"), $"{output}\r\n{error}");
|
||||
await File.WriteAllTextAsync(Path.Combine(Global.NetchDir, $"logging\\{Name}.log"), $"{output}\r\n{error}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -1110,7 +1110,7 @@ namespace Netch.Forms
|
||||
await NatTest();
|
||||
}
|
||||
|
||||
private readonly object _natTestLock = new();
|
||||
private bool _natTestLock = true;
|
||||
|
||||
/// <summary>
|
||||
/// 测试 NAT
|
||||
@@ -1120,13 +1120,16 @@ namespace Netch.Forms
|
||||
if (!MainController.Mode!.TestNatRequired())
|
||||
return;
|
||||
|
||||
if (!Monitor.TryEnter(_natTestLock))
|
||||
if (!_natTestLock)
|
||||
return;
|
||||
|
||||
_natTestLock = false;
|
||||
|
||||
try
|
||||
{
|
||||
NatTypeStatusText(i18N.Translate("Starting NatTester"));
|
||||
|
||||
// Monitor.TryEnter() Monitor.Exit() (a.k.a. lock) not work with async/await
|
||||
var (result, _, publicEnd) = await MainController.NTTController.Start();
|
||||
|
||||
if (!string.IsNullOrEmpty(publicEnd))
|
||||
@@ -1141,7 +1144,7 @@ namespace Netch.Forms
|
||||
}
|
||||
finally
|
||||
{
|
||||
Monitor.Exit(_natTestLock);
|
||||
_natTestLock = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user