{"record":{"id":"0e7d62a55fb71cc6","repo":"stride3d/stride","slug":"this-window-has-already-been-shown-as-blocking","errorCode":null,"errorMessage":"This window has already been shown as blocking.","messagePattern":"This window has already been shown as blocking\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Windows/WindowManager.cs","lineNumber":127,"sourceCode":"            AllWindowsList.Add(MainWindow);\n\n            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;\n            window.Show();\n        }\n\n        /// <summary>\n        /// Shows the given window as blocking window. A blocking window will always block the main window of the application, even if shown before it, but does not\n        /// affect modal windows. However it can still be blocked by them..\n        /// </summary>\n        /// <param name=\"window\">The blocking window to show.</param>\n        public static void ShowBlockingWindow([NotNull] Window window)\n        {\n            if (window == null) throw new ArgumentNullException(nameof(window));\n            CheckDispatcher();\n\n            var windowInfo = new WindowInfo(window) { IsBlocking = true };\n            if (BlockingWindowsList.Contains(windowInfo))\n                throw new InvalidOperationException(\"This window has already been shown as blocking.\");\n\n            window.Owner = MainWindow?.Window;\n            window.WindowStartupLocation = MainWindow != null ? WindowStartupLocation.CenterOwner : WindowStartupLocation.CenterScreen;\n\n            AllWindowsList.Add(windowInfo);\n            BlockingWindowsList.Add(windowInfo);\n\n            // Disable the main window now so the blocking window is recognized as modal when shown.\n            RefreshDisabledStates();\n\n            // Update the hwnd on load in case the window is closed before being shown\n            // We will receive EVENT_OBJECT_HIDE but not EVENT_OBJECT_SHOW in this case.\n            window.Loaded += (sender, e) => windowInfo.ForceUpdateHwnd();\n            window.Closed += (sender, e) => ActivateMainWindow();\n\n            Logger.Info($\"Modal window showing. ({window})\");\n            window.Show();\n        }","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Windows/WindowManager.cs#L109-L145","documentation":"ShowBlockingWindow tracks every blocking (modal) window in BlockingWindowsList. Showing the same window again while it is already registered as blocking is rejected with InvalidOperationException, since a modal window cannot be shown modally twice.","triggerScenarios":"Calling ShowBlockingWindow on a Window instance that is already in the blocking list — e.g. double-click triggering a second ShowDialog, or re-showing a dialog that was never closed/removed.","commonSituations":"Double-invocation from a button click handler; re-entrant command execution while a modal dialog is open; retaining a Window instance and re-showing it after it was already shown modally.","solutions":["Guard the call: only call ShowBlockingWindow if the window is not already shown (track with a bool or window.IsEnabled/visibility check)","Disable the trigger (button/command) while the blocking window is open","Create a new Window instance for each modal presentation instead of reusing one","Wrap in try/catch on InvalidOperationException as a last resort if re-entrancy is unavoidable"],"exampleFix":"// before\nprivate void OnClick(object s, RoutedEventArgs e) => windowManager.ShowBlockingWindow(myDialog);\n// after\nprivate void OnClick(object s, RoutedEventArgs e)\n{\n    if (myDialog.IsVisible) return;\n    windowManager.ShowBlockingWindow(myDialog);\n}","handlingStrategy":"validation","validationCode":"if (!myDialog.IsVisible && !isBlockingShown) windowManager.ShowBlockingWindow(myDialog);","typeGuard":null,"tryCatchPattern":"try { windowManager.ShowBlockingWindow(dialog); } catch (InvalidOperationException) { /* dialog already blocking; ignore or focus it */ }","preventionTips":["Disable buttons/commands while a modal dialog is open","Never reuse a Window instance for concurrent modal shows","Track blocking-window state in a bool in your view-model"],"tags":["wpf","window-management","reentrancy"],"backgroundTag":"invalid-state-transition","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}