void StartCore(string config) { if (v2rayCore != null) { Debug.WriteLine("v2ray core is running, skip."); return; } Debug.WriteLine("start v2ray core"); var fileName = resData("Executable"); v2rayCore = new Process(); v2rayCore.StartInfo.FileName = fileName; v2rayCore.StartInfo.Arguments = "-config=stdin: -format=json"; v2rayCore.EnableRaisingEvents = true; v2rayCore.Exited += (s, e) => { LogMsg(I18N("CoreExit")); }; // set up output redirection v2rayCore.StartInfo.CreateNoWindow = true; v2rayCore.StartInfo.UseShellExecute = false; v2rayCore.StartInfo.RedirectStandardOutput = true; v2rayCore.StartInfo.RedirectStandardError = true; v2rayCore.StartInfo.RedirectStandardInput = true; // see below for output handler v2rayCore.ErrorDataReceived += LogDeliver; v2rayCore.OutputDataReceived += LogDeliver; try { v2rayCore.Start(); Lib.ChildProcessTracker.AddProcess(v2rayCore); v2rayCore.StandardInput.WriteLine(config); v2rayCore.StandardInput.Close(); } catch (Exception e) { Debug.WriteLine("Excep: {0}", e); MessageBox.Show(I18N("CantLauchCore")); StopCore(); return; } v2rayCore.BeginErrorReadLine(); v2rayCore.BeginOutputReadLine(); OnCoreStatChange?.Invoke(this, null); }
public void StopCore() { if (v2rayCore != null) { Debug.WriteLine("kill v2ray core"); Lib.Utils.KillProcessAndChildrens(v2rayCore.Id); if (!v2rayCore.HasExited) { v2rayCore.WaitForExit(3000); } } else { Debug.WriteLine("v2ray-core is not runnig!"); } v2rayCore = null; OnCoreStatChange?.Invoke(this, null); }