-4

Is there anything I can do with my program wherein I have to do something when my application has been terminated using task manager?

I hope you can help me in this matter.

Thank you!

jejerome
  • 168
  • 13
  • what kind of program? console/windows/web? – Rahul Sep 08 '17 at 08:46
  • 3
    Your program can always be terminated with *no* notice (think power cut). If there's something you "have" to do before exit, consider re-architecting your solution so that you instead can *recover* during startup - which doesn't tend to have the same time pressures. – Damien_The_Unbeliever Sep 08 '17 at 08:48
  • @Rahul I have a windows application that shells an outside application (.exe). What i want to achieve, is when the user terminates my windows application thru task manager, the shelled outside application should also be terminated. – jejerome Sep 08 '17 at 08:49
  • I am asking myself: Why do you think a user may want to do this? Is your program prone to getting unresponsive to the point where the user considers your app to stall? If so, then you maybe want to fix *that*. – Fildor Sep 08 '17 at 09:02
  • "that shells an outside application (.exe)" - is that a child process? Have you tried if it already gets killed? – Fildor Sep 08 '17 at 09:04

2 Answers2

1

You can´t do this because the applications process is forcefully closed (killed). Events only happen if the application is asked to end e.g. call Close() or Exit().

If you need to do something when this happens implement a different app that monitors your app to take actions e.g. restart app or close another app.

Tom Schardt
  • 470
  • 1
  • 7
  • 18
0

I have a windows application that shells an outside application (.exe). What i want to achieve, is when the user terminates my windows application thru task manager, the shelled outside application should also be terminated.

As pointed out by others, you simply cannot do this, because when a process is killed, it receives no events at all. What you can do, however, if this requirement is super important, that you deploy a second program, which is a windows service, that monitors your windows app and shuts down the shelled application whenever it finds that your app is not running any more.

Márton Balassa
  • 818
  • 7
  • 11