Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,7 @@ internal virtual void DoShutdown()
// in the function that calls us.

// We use a while loop like this because closing a window will modify the windows list.
while(WindowsInternal.Count > 0)
while (WindowsInternal.Count > 0)
{
if (!WindowsInternal[0].IsDisposed)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4511,16 +4511,9 @@ private void UpdateWindowListsOnClose()
App.WindowsInternal.Remove(this);

// Check to see if app should shut down--this behavior really belongs in Application
if (!_appShuttingDown)
if (!_appShuttingDown && ShouldCloseApplication())
{
// If this is the last window that's closing and shutdownmode is onlastwindowclose, or
// if this is the main window closing and shutdownmode is onmainwindowclose, shutdown
// the app
if (((App.Windows.Count == 0) && (App.ShutdownMode == ShutdownMode.OnLastWindowClose))
|| ((App.MainWindow == this) && (App.ShutdownMode == ShutdownMode.OnMainWindowClose)))
{
App.CriticalShutdown(0);
}
App.CriticalShutdown(0);
}

TryClearingMainWindow();
Expand All @@ -4530,7 +4523,33 @@ private void UpdateWindowListsOnClose()
App.NonAppWindowsInternal.Remove(this);
}
}
}
}

private bool ShouldCloseApplication()
{
if (App.ShutdownMode is ShutdownMode.OnLastWindowClose)
{
// 1) If this is the last window and shutdown mode is OnLastWindowClose, then we can close the app
// 2) We should also close the app if all of the remaining windows are windows that were created,
// -- but never shown (excludes inits via EnsureHandle via WindowInteropHelper, such windows are considered shown).
lock (App.WindowsInternal.SyncRoot)
{
for (int i = App.WindowsInternal.Count - 1; i >= 0; i--)
{
if (!App.WindowsInternal[i].IsSourceWindowNull)
{
return false;
}
}
}

return true;
}

// If this is the main window and shutdown mode is OnMainWindowClose, then we can close the app
return App.ShutdownMode is ShutdownMode.OnMainWindowClose && App.MainWindow == this;
}

private bool WmDestroy()
{
// For WS_CHILD window, WM_SIZE, WM_MOVE (and maybe others) are called
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

//
Expand Down Expand Up @@ -167,11 +167,11 @@ internal void RemoveAt(int index)
{
lock (_list.SyncRoot)
{
_list.Remove(index);
_list.RemoveAt(index);
}
}

internal int Add (Window win)
internal int Add(Window win)
{
lock (_list.SyncRoot)
{
Expand Down Expand Up @@ -201,7 +201,7 @@ internal bool HasItem(Window win)
//
//------------------------------------------------------
#region Private Fields
private ArrayList _list;
private readonly ArrayList _list;
#endregion Private Fields
}

Expand Down