Capturing Process Termination(Task Manager) in WPF

1.6k Views Asked by At

I have a WPF application.when the application closes i do some update/insert action in database which is mandatory for my application.But if my application is forcibly closed by killing the process in taskmanager, i am not able to do operation in database.

I am doing the updating/insertingrecords in DB in "Exit" Event in "App.xaml.cs",this event is not fired when the application is killed in taskmanager.By searching i found that if a process is killed in Process Tab of Task Manager the application closes immediately without waiting for the application to respond.

One way we can capture the process termination is by having a service running which checks this application Process.

Is there any other way to catch the process termination within the same application i.e By not having another service running to check.?

Thanks in advance..

1

There are 1 best solutions below

1
On

TerminateProcess does not give your application any chance to detect termination. You need an external application/service that monitors, or better yet you need to take away the reason your users have to kill the process using Task Manager.