- skyflashde
- Posts: 5
- Joined:
NoesisApp.Application never calls Window Unloaded event on app.Shutdown();
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!
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!
- skyflashde
- Posts: 5
- Joined:
Re: NoesisApp.Application never calls Window Unloaded event on app.Shutdown();
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?
- 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?
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: NoesisApp.Application never calls Window Unloaded event on app.Shutdown();
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
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 39 guests