There is a WPF application.
i want to log when the application is closed.
but i cannot modify the application (some restriction, just because business).
So i create an invisible form component live inside the existing application, add as a dll library, so the existing application do not need to be modified.
but the issue is, how can my invisible component know the application is shutting down?
is there some function or event handler i can use?
Solution:
there are some event can do that,
UnLoaded Closing Closed
all these three events will be fired when the main windows is going to be closed.
Problem solved
have you checked the FormClosing event?
I still have not got the knowledge of WPF but I do know from winforms, there is an event
Closing
from theForm
class, which you can trap and present the dialog 'This application is exiting, do you wish to continue etc', and set theCancel
flag to true to abort closing the form, also there isApplicationExit
event from theApplication
class, you can trap that if you want to handle the shutting down of the application.Hope this helps, Best regards, Tom.
The
System.Windows.Window
class has a virtualOnClosing(CancelEventArgs)
method that can be overridden for this, and aClosing
event that can be handled.I typically capture these events and pass the information on to the
Page
classes, which, sadly, contain no such methods or events.Each window will fire these methods when it is closed, so it is not necessary to wire-up any messages between parent and child windows. And, I believe, the Task Manager will first attempt to do a normal shut-down of the application, which will cause the close events to fire, unless something else, like a dialog box, prevents it. Only after that is attempted will TM ask if the an abnormal end is to be performed for the application, which will, obviously, circumvent the Closing event.