From 74149b761f95684d109b660b2d6bf59ffa80a8d8 Mon Sep 17 00:00:00 2001 From: Minghao Hu Date: Mon, 12 Feb 2024 22:49:57 +0900 Subject: [PATCH] Resolve the `StatePort` when the other components call it. --- v2rayN/v2rayN/Handler/LazyConfig.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/v2rayN/v2rayN/Handler/LazyConfig.cs b/v2rayN/v2rayN/Handler/LazyConfig.cs index 51231eba..89953f82 100644 --- a/v2rayN/v2rayN/Handler/LazyConfig.cs +++ b/v2rayN/v2rayN/Handler/LazyConfig.cs @@ -11,14 +11,24 @@ namespace v2rayN.Handler public static LazyConfig Instance => _instance.Value; - private int _statePort; - public int StatePort { get => _statePort; } - private Job _processJob = new(); + private int? _statePort; + public int StatePort + { + get + { + if (_statePort is null) + { + _statePort = Utils.GetFreePort(); + } + + return _statePort.Value; + } + } + + private Job _processJob = new(); public LazyConfig() { - _statePort = Utils.GetFreePort(); - SqliteHelper.Instance.CreateTable(); SqliteHelper.Instance.CreateTable(); SqliteHelper.Instance.CreateTable(); @@ -68,7 +78,7 @@ namespace v2rayN.Handler } return localPort; } - + public void AddProcess(IntPtr processHandle) { _processJob.AddProcess(processHandle);