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:
1 parent
d3b071b0be
commit
05a5169129
2 files changed
+20
No files matched your search
@@ -63,6 +63,16 @@ public sealed class AppServices : IDisposable
|
||||
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>
|
||||
/// Persists the configuration when this session changed a setting; called
|
||||
/// once at shutdown. A write failure only loses this session's settings
|
||||
|
||||
@@ -113,8 +113,18 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
||||
/// <param name="folderPath">The workspace folder.</param>
|
||||
/// <param name="session">The opened workspace session.</param>
|
||||
private void ShowWorkspace(string folderPath, WorkspaceSession session)
|
||||
{
|
||||
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}";
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user