views:

75

answers:

2

I've got the following code in a window B that is started in its own thread from a window A.

view.Closing += (sender, e) =>
{
    view.Visibility = Visibility.Collapsed;
    e.Cancel = true;
};

When I close window A window B remains in memory and the application doesn't dispose. How should I go forward make sure that the application is shut down when closing window A.

edit: the window B takes a while to load and build that's why the code is there.

+2  A: 

use Application.Exit();

For WPF: Application.Current.Shutdown();

Ruel
just like that?
Makach
Yes, it will exit your application.
Ruel
I edited the Tags: XBap means not WinForms.
Henk Holterman
I see, sorry about that.
Ruel
+2  A: 

Basic solution: Window A needs to keep a ref to Window B and Dispose() it.

You may have to make the Cancel logic in B conditional.

Henk Holterman
Application.Current.Shutdown() seems to be working fine. Should I go the (slightly) longer route and do what you propose here?
Makach
Not directly necessary, it might be advisable if you have lots of cleanup to do in the Window(s)
Henk Holterman