diff --git a/src/BD.WTTS.Client.Avalonia/UI/Views/Windows/MainWindow.axaml.cs b/src/BD.WTTS.Client.Avalonia/UI/Views/Windows/MainWindow.axaml.cs index 69d09019bba..8cf9bb483ef 100644 --- a/src/BD.WTTS.Client.Avalonia/UI/Views/Windows/MainWindow.axaml.cs +++ b/src/BD.WTTS.Client.Avalonia/UI/Views/Windows/MainWindow.axaml.cs @@ -44,10 +44,14 @@ internal bool SetStartDefaultPageName() if (NavigationService.Instance.CurrnetPage != null) return false; + var mw2 = IViewModelManager.Instance.MainWindow2; + if (mw2 == null) + return false; + Type? pageType = null; if (!string.IsNullOrEmpty(UISettings.StartDefaultPageName.Value)) { - var tabItems = IViewModelManager.Instance.MainWindow2?.TabItems; + var tabItems = mw2?.TabItems; if (tabItems == null) return false; diff --git a/src/BD.WTTS.Client/Services/Mvvm/UI/ViewModels/ViewModelManager.cs b/src/BD.WTTS.Client/Services/Mvvm/UI/ViewModels/ViewModelManager.cs index 0c9247aeea8..0d3522ffc61 100644 --- a/src/BD.WTTS.Client/Services/Mvvm/UI/ViewModels/ViewModelManager.cs +++ b/src/BD.WTTS.Client/Services/Mvvm/UI/ViewModels/ViewModelManager.cs @@ -4,8 +4,8 @@ namespace BD.WTTS.Services.Implementation; internal sealed class ViewModelManager : ReactiveObject, IViewModelManager { bool disposedValue; - Dictionary viewModelDataCaches = new(); - Dictionary viewModelCaches = new(); + ConcurrentDictionary viewModelDataCaches = new(); + ConcurrentDictionary viewModelCaches = new(); /// /// 获取为当前主窗口提供的数据 @@ -69,7 +69,8 @@ public void Dispose(ViewModelBase viewModel) var vmType = viewModel.GetType(); var value = Serializable.SMP2(vmType, viewModel); viewModelDataCaches[vmType] = value; - viewModelCaches.Remove(vmType); + viewModelDataCaches[vmType] = value; + viewModelCaches.TryRemove(vmType, out var _); } void Dispose(bool disposing)