This commit is contained in:
chao wan 2024-04-05 18:57:41 +08:00
parent 5878929430
commit ed1a1f50af

View file

@ -32,20 +32,23 @@ namespace v2rayN.Handler
public void LoadCore(bool isForce = false) public void LoadCore(bool isForce = false)
{ {
List<AutoResetEvent> executingResetEvents; AutoResetEvent? loadResetEvent = default;
List<AutoResetEvent>? executingResetEvents = default;
lock (loadResetEvents) lock (loadResetEvents)
{ {
if (isForce && isLoading) if (!isForce && isLoading)
{ {
var loadResetEvent = new AutoResetEvent(false); loadResetEvent = new AutoResetEvent(false);
lock (loadResetEvents) loadResetEvents.Add(loadResetEvent); loadResetEvents.Add(loadResetEvent);
loadResetEvent.WaitOne();
return;
} }
else
{
isLoading = true; isLoading = true;
executingResetEvents = new(loadResetEvents); executingResetEvents = new(loadResetEvents);
loadResetEvents.Clear(); loadResetEvents.Clear();
} }
}
if (loadResetEvent?.WaitOne() == true) return;
var node = ConfigHandler.GetDefaultServer(_config); var node = ConfigHandler.GetDefaultServer(_config);
string fileName = Utils.GetConfigPath(Global.CoreConfigFileName); string fileName = Utils.GetConfigPath(Global.CoreConfigFileName);
var result = CoreConfigHandler.GenerateClientConfig(node!, fileName, out string msg, out string content); var result = CoreConfigHandler.GenerateClientConfig(node!, fileName, out string msg, out string content);
@ -57,7 +60,7 @@ namespace v2rayN.Handler
Utils.RemoveDeviceForPnputil(Utils.GetSingboxTunDeviceInstanceId(Global.DefaultSingboxTunDeviceName)); Utils.RemoveDeviceForPnputil(Utils.GetSingboxTunDeviceInstanceId(Global.DefaultSingboxTunDeviceName));
CoreStart(node); CoreStart(node);
} }
executingResetEvents.ForEach(result => result.Set()); executingResetEvents?.ForEach(result => result.Set());
lock(loadResetEvents) lock(loadResetEvents)
{ {
if(loadResetEvents.Count > 0) if(loadResetEvents.Count > 0)