From 05a51691298802c2fbff0115e86ca1a7628c7446 Mon Sep 17 00:00:00 2001 From: doyaGu Date: Sat, 3 Oct 2026 09:01:15 -0400 Subject: [PATCH] fix(workspace): release the session when the workspace view cannot be built If the first board read failed while WorkspaceViewModel was being constructed, the open-failed page appeared but the lock and connection stayed held until exit, which blocked other instances. The session is now closed before the error page is shown. --- YKanBan/Services/AppServices.cs | 10 ++++++++++ YKanBan/ViewModels/MainWindowViewModel.cs | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/YKanBan/Services/AppServices.cs b/YKanBan/Services/AppServices.cs index be70d9c..3e719e8 100644 --- a/YKanBan/Services/AppServices.cs +++ b/YKanBan/Services/AppServices.cs @@ -63,6 +63,16 @@ public sealed class AppServices : IDisposable return Session; } + /// + /// Releases the open workspace session, if any, so its lock and connection + /// do not outlive a workspace that could not be shown. + /// + public void CloseWorkspace() + { + Session?.Dispose(); + Session = null; + } + /// /// Persists the configuration when this session changed a setting; called /// once at shutdown. A write failure only loses this session's settings diff --git a/YKanBan/ViewModels/MainWindowViewModel.cs b/YKanBan/ViewModels/MainWindowViewModel.cs index ea712c7..c55db3b 100644 --- a/YKanBan/ViewModels/MainWindowViewModel.cs +++ b/YKanBan/ViewModels/MainWindowViewModel.cs @@ -114,7 +114,17 @@ public sealed partial class MainWindowViewModel : ViewModelBase /// The opened workspace session. private void ShowWorkspace(string folderPath, WorkspaceSession session) { - Content = new WorkspaceViewModel(session, ShowSettings, ShowAbout, _services.Config, _dialogs); + try + { + Content = new WorkspaceViewModel(session, ShowSettings, ShowAbout, _services.Config, _dialogs); + } + catch + { + // The first board read failed: the caller shows an error page, which holds no workspace. + _services.CloseWorkspace(); + throw; + } + Title = $"{new DirectoryInfo(folderPath).Name} - {Resources.App_Name}"; }