-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMainWindow.SafeVisibilityLifecycle.cs
More file actions
44 lines (38 loc) · 1.58 KB
/
Copy pathMainWindow.SafeVisibilityLifecycle.cs
File metadata and controls
44 lines (38 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2026 Ari Sulistiono
// SPDX-License-Identifier: Apache-2.0
using System.Windows;
namespace ArIED61850Tester;
public partial class MainWindow
{
/// <summary>
/// Makes every unqualified Show() call in the MainWindow partial class lifecycle-safe.
///
/// The IO FAT workspace is an owned window. When the application exits, WPF closes
/// the owner and its owned FAT window as one native-window chain. The FAT Closed
/// callback must not try to make the owner visible again while that owner is already
/// inside Window.VerifyNotClosing(). During normal Engineering ↔ FAT switching this
/// method delegates directly to Window.Show(), preserving the instant hide/show flow.
/// </summary>
public new void Show()
{
if (IsApplicationWindowShutdownInProgress())
return;
try
{
base.Show();
}
catch (InvalidOperationException) when (IsApplicationWindowShutdownInProgress())
{
// Shutdown can begin between the guard above and Window.Show(). This is a
// benign owned-window teardown race, not an application error.
}
}
private bool IsApplicationWindowShutdownInProgress()
{
if (_shutdownStarted || _allowClose || Dispatcher.HasShutdownStarted || Dispatcher.HasShutdownFinished)
return true;
var applicationDispatcher = Application.Current?.Dispatcher;
return applicationDispatcher is not null &&
(applicationDispatcher.HasShutdownStarted || applicationDispatcher.HasShutdownFinished);
}
}