I want to call a c# function when my application is closed using task manager or abruptly.
I want to perform some operations there.
Please Help me.
Thanks in advance.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Apr 30, 2013, 7:10 PM
So there's no problem trapping these actions and the only ones where you need to set CloseReason.User manually are those where the form is closed programatically.
VulpesPosted Apr 30, 2013, 7:16 AM
So to determine which applies you have to set CloseReason to EndTask by default and then when the user performs some action such as clicking a button to close the form, you have to manually set CloseReason to User.
If CloseReason is still set to EndTask when the form closes then it must have been closed via Task Manager.
It's not very satisfactory but it seems to be the only way to do it.
Vivek AryaPosted Apr 30, 2013, 5:35 AM
It does not show any type of message that application is going to close, when the application is closed using Task Manager.
VulpesPosted Apr 30, 2013, 5:19 AM
Unfortunately, the Window.Closing or Closed event in WPF doesn't have this and you therefore have to resort to examining the underlying Win32 mesage to get this information.
I found this thread which explains how to do it:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/549a4bbb-e77b-4c5a-b724-07996774c60a
Vivek AryaPosted Apr 30, 2013, 3:03 AM