skyflashde
Topic Author
Posts: 5
Joined: 17 May 2019, 16:35

NoesisApp.Application never calls Window Unloaded event on app.Shutdown();

20 May 2019, 09:43

My next problem is that I need to unload stuff when the app shut down. There are many ways to close the application, and I need to catch them all.
They all go to an app.Shutdown(); call, but this doesn't seem to trigger the Unloaded event in the Window.

Now I could call the code in the Window myself, but how do I get the Window from the Application object?

I can't find this property:

https://docs.microsoft.com/de-de/dotnet ... mework-4.8

It should be in Noesis:

https://www.noesisengine.com/docs/2.2/A ... ation.html

So how do I access it? Or is there another way?

How do I trigger the MainWindow.Unloaded event?

Thank you!

Tags:
 
skyflashde
Topic Author
Posts: 5
Joined: 17 May 2019, 16:35

Re: NoesisApp.Application never calls Window Unloaded event on app.Shutdown();

20 May 2019, 10:50

Some more stuff I found while testing ways to terminate the application:

- Closing the Window calls Window.Shutdown() but not Window.Close().

- Closing the App calls Window.Close() but not Window.Shutdown()

- Terminating a console app via STRG+C calls Window.Close(), then Window.Shutdown()

This confuses me. What IS the correct way to teardown the application and the window?
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: NoesisApp.Application never calls Window Unloaded event on app.Shutdown();

21 May 2019, 12:59

Hi, you have some good points here...

The Application.MainWindow property is missing in Noesis so we will add it for next release: https://www.noesisengine.com/bugs/view.php?id=1473
Unfortunately there is no way now to get the main window other than keep a reference in its code-behind when it gets created.

There are also a bunch of events missing in the Window class like Activated, Deactivated, Closing, Closed... We will add them as soon as possible: https://www.noesisengine.com/bugs/view.php?id=1474

Regarding the application termination, what I can reproduce is the following:
- If I close the window using top-right close button, then Application.Finish() and Window.Shutdown() get called.
- If I add a button that calls MainWindow.Close(), then Application.Finish() and Window.Shutdown() get called.
- If I add a button that calls Application.Shutdown(), then MainWindow.Close() gets called, next Application.Finish() and Window.Shutdown() get called.

They all end going through Application.Finish(). Application exposes an Exit event that is generated inside Finish(), could that be the point you are looking for unloading your stuff? You can just override the OnExit method in your application to add that code.

Anyway I noticed, as you pointed, that Window.Unloaded event is not fired, and that is a bug, so we will fix it in future versions: https://www.noesisengine.com/bugs/view.php?id=1475

Who is online

Users browsing this forum: No registered users and 0 guests