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.
This commit is contained in:
doyaGu committed 2026-10-03 09:01:15 -04:00
1 parent d3b071b0be
commit 05a5169129
2 files changed
+21 -1

No files matched your search

+10
View File
@@ -63,6 +63,16 @@ public sealed class AppServices : IDisposable
return Session; return Session;
} }
/// <summary>
/// Releases the open workspace session, if any, so its lock and connection
/// do not outlive a workspace that could not be shown.
/// </summary>
public void CloseWorkspace()
{
Session?.Dispose();
Session = null;
}
/// <summary> /// <summary>
/// Persists the configuration when this session changed a setting; called /// Persists the configuration when this session changed a setting; called
/// once at shutdown. A write failure only loses this session's settings /// once at shutdown. A write failure only loses this session's settings
+11 -1
View File
@@ -114,7 +114,17 @@ public sealed partial class MainWindowViewModel : ViewModelBase
/// <param name="session">The opened workspace session.</param> /// <param name="session">The opened workspace session.</param>
private void ShowWorkspace(string folderPath, WorkspaceSession 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}"; Title = $"{new DirectoryInfo(folderPath).Name} - {Resources.App_Name}";
} }