From bb3a04a9c807b7e3cdfc627ec8b705564704fcbc Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:26:12 +0800 Subject: [PATCH] Bug fix for exit app --- v2rayN/v2rayN/App.xaml.cs | 10 ++++++++- .../v2rayN/ViewModels/MainWindowViewModel.cs | 22 +++++++------------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/v2rayN/v2rayN/App.xaml.cs b/v2rayN/v2rayN/App.xaml.cs index b61aad77..6b44f961 100644 --- a/v2rayN/v2rayN/App.xaml.cs +++ b/v2rayN/v2rayN/App.xaml.cs @@ -1,4 +1,5 @@ -using System.Windows; +using System.Diagnostics; +using System.Windows; using System.Windows.Threading; using v2rayN.Handler; using v2rayN.Model; @@ -81,5 +82,12 @@ namespace v2rayN { Logging.SaveLog("TaskScheduler_UnobservedTaskException", e.Exception); } + + protected override void OnExit(ExitEventArgs e) + { + Logging.SaveLog("OnExit"); + base.OnExit(e); + Process.GetCurrentProcess().Kill(); + } } } \ No newline at end of file diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index fba6486e..eaee1d1c 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -597,7 +597,7 @@ namespace v2rayN.ViewModels private void OnProgramStarted(object state, bool timeout) { - Application.Current.Dispatcher.Invoke((Action)(() => + Application.Current?.Dispatcher.Invoke((Action)(() => { ShowHideWindow(true); })); @@ -638,7 +638,7 @@ namespace v2rayN.ViewModels { try { - Application.Current.Dispatcher.Invoke((Action)(() => + Application.Current?.Dispatcher.Invoke((Action)(() => { if (!_showInTaskbar) { @@ -684,7 +684,7 @@ namespace v2rayN.ViewModels private void UpdateSpeedtestHandler(string indexId, string delay, string speed) { - Application.Current.Dispatcher.Invoke((Action)(() => + Application.Current?.Dispatcher.Invoke((Action)(() => { SetTestResult(indexId, delay, speed); })); @@ -747,7 +747,6 @@ namespace v2rayN.ViewModels { Logging.SaveLog("MyAppExit Begin"); - StorageUI(); ConfigHandler.SaveConfig(_config); //HttpProxyHandle.CloseHttpAgent(config); @@ -772,7 +771,6 @@ namespace v2rayN.ViewModels finally { Application.Current.Shutdown(); - Environment.Exit(0); } } @@ -848,7 +846,7 @@ namespace v2rayN.ViewModels }).OrderBy(t => t.sort).ToList(); _lstProfile = JsonUtils.Deserialize>(JsonUtils.Serialize(lstModel)); - Application.Current.Dispatcher.Invoke((Action)(() => + Application.Current?.Dispatcher.Invoke((Action)(() => { _profileItems.Clear(); _profileItems.AddRange(lstModel); @@ -1186,7 +1184,7 @@ namespace v2rayN.ViewModels (new UpdateHandle()).RunAvailabilityCheck((bool success, string msg) => { _noticeHandler?.SendMessage(msg, true); - Application.Current.Dispatcher.Invoke((Action)(() => + Application.Current?.Dispatcher.Invoke((Action)(() => { if (!_showInTaskbar) { @@ -1509,7 +1507,7 @@ namespace v2rayN.ViewModels { TestServerAvailability(); - Application.Current.Dispatcher.Invoke((Action)(() => + Application.Current?.Dispatcher.Invoke((Action)(() => { BlReloadEnabled = true; })); @@ -1559,7 +1557,7 @@ namespace v2rayN.ViewModels SysProxyHandle.UpdateSysProxy(_config, _config.tunModeItem.enableTun ? true : false); _noticeHandler?.SendMessage(ResUI.TipChangeSystemProxy + _config.sysProxyType.ToString(), true); - Application.Current.Dispatcher.Invoke((Action)(() => + Application.Current?.Dispatcher.Invoke((Action)(() => { BlSystemProxyClear = (type == ESysProxyType.ForcedClear); BlSystemProxySet = (type == ESysProxyType.ForcedChange); @@ -1708,10 +1706,6 @@ namespace v2rayN.ViewModels } } - private void StorageUI() - { - } - private void BindingUI() { ColorModeDark = _config.uiItem.colorModeDark; @@ -1873,7 +1867,7 @@ namespace v2rayN.ViewModels .Delay(TimeSpan.FromSeconds(1)) .Subscribe(x => { - Application.Current.Dispatcher.Invoke(() => + Application.Current?.Dispatcher.Invoke(() => { ShowHideWindow(false); });