Close Portal on the first click of the X #18

Merged
oss merged 1 commit from fix/close-on-first-click into main 2026-11-05 19:33:16 +01:00
Owner

Closing Portal with nothing running showed "Something went wrong: Cannot set Visibility to Visible or call Show, ShowDialog, Close, or WindowInteropHelper.EnsureHandle while a Window is closing". A second click on the X then closed it.

Cause

MainWindow.OnClosing cancels the close, waits for the close confirmation and the session shutdown, and then calls Close() again. With no transfers running, those waits finish immediately, so the second Close() ran inside the first Closing event. WPF refuses that. The second click worked because the close was already marked as confirmed.

Fix

The final Close() is queued with Dispatcher.BeginInvoke, so it runs after the first close has finished.

Verification

Check Result
dotnet build 0 warnings, 0 errors
dotnet test Portal.slnx 171 passed, 17 skipped by design
Closing the real window Not run. UI checks belong on the Windows CI VM, which still waits for oss/Forgejo-VM-MCP#14. The owner can confirm it with the installed build.

🤖 Generated with Claude Code

Closing Portal with nothing running showed "Something went wrong: Cannot set Visibility to Visible or call Show, ShowDialog, Close, or WindowInteropHelper.EnsureHandle while a Window is closing". A second click on the X then closed it. ## Cause `MainWindow.OnClosing` cancels the close, waits for the close confirmation and the session shutdown, and then calls `Close()` again. With no transfers running, those waits finish immediately, so the second `Close()` ran inside the first `Closing` event. WPF refuses that. The second click worked because the close was already marked as confirmed. ## Fix The final `Close()` is queued with `Dispatcher.BeginInvoke`, so it runs after the first close has finished. ## Verification | Check | Result | |---|---| | `dotnet build` | 0 warnings, 0 errors | | `dotnet test Portal.slnx` | 171 passed, 17 skipped by design | | Closing the real window | Not run. UI checks belong on the Windows CI VM, which still waits for https://git.ossalali.com/oss/Forgejo-VM-MCP/pulls/14. The owner can confirm it with the installed build. | 🤖 Generated with [Claude Code](https://claude.com/claude-code)
OnClosing cancels the close, waits for the confirmation and the session
shutdown, then closes again. With nothing running those waits finish at
once, so the second Close() ran inside the first Closing event and WPF
refused it with "Cannot ... Close ... while a Window is closing". The
second close is now queued until the first has finished.
oss merged commit d6f7149840 into main 2026-11-05 19:33:16 +01:00
oss deleted branch fix/close-on-first-click 2026-11-05 19:33:16 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
oss/Portal!18
No description provided.