Hanlde Event when C# exe is aborted abruptly
-
Hi all, I have a windows C# EXE. In most cases, it will be killed abruptly from TaskManager (its session will be killed). Is there any Event in C# to handle those abruptly closing of EXE? Need in urgent. Thanx in advance vidh
If you kill something from the task manager the idea is that it should stop dead right there and then. Before Vista you were trusted to be able to hook into the system shutdown events and even stop the shutdown if needed. THis was abused way too much and iirc Vista now will notify you, give you a few seconds, and then carry on anyway. It'd be just the same with a kill command from the task manager, if the OS allowed you to intervine it would be abused a lot and so just isn't there. On a personal note if I tried to kill an app and it declined I would be very angry, it's my machine and I know what I want to happen better than the app does, I didn't click End Process by accident!
-
Hi all, I have a windows C# EXE. In most cases, it will be killed abruptly from TaskManager (its session will be killed). Is there any Event in C# to handle those abruptly closing of EXE? Need in urgent. Thanx in advance vidh
harvid wrote:
Is there any Event in C# to handle those abruptly closing of EXE?
TaskManager will TRY and close the app nicely first. This is a normal close event on the main form of your application. If your app doesn't respond, it'll just be stopped and killed. There is no event and no chance for your code to even care. It's the "bullet in the brain" method of killing your app.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Hi all, I have a windows C# EXE. In most cases, it will be killed abruptly from TaskManager (its session will be killed). Is there any Event in C# to handle those abruptly closing of EXE? Need in urgent. Thanx in advance vidh
Like Dave and originSH said, the purpose of the task manager is to stop a task/process pretty much in it's tracks. You can try the
OnClose
method, but it might not do you a whole alot. Letting task manager do it's bit by shutting down the app with no intervention done by the app is what should be intended. Nothing more irritating than telling task manager over and over to kill a process because it won't go away."The clue train passed his station without stopping." - John Simmons / outlaw programmer
-
Like Dave and originSH said, the purpose of the task manager is to stop a task/process pretty much in it's tracks. You can try the
OnClose
method, but it might not do you a whole alot. Letting task manager do it's bit by shutting down the app with no intervention done by the app is what should be intended. Nothing more irritating than telling task manager over and over to kill a process because it won't go away."The clue train passed his station without stopping." - John Simmons / outlaw programmer
Hi Dave,Paul and originSH, Thanks a lot for your comments. Let me explain my actual scenario, I have a C# Windows EXE which will call my Webserive hosted in another Webserver asynchronously. We have an UI interface which will call the above mentioned C# Windows EXE. when EXE gets abruptly aborted from UI Interface, my webservice still running in webserver machine. Any options or methods to stop my webservice when my EXE stops abruptly? Pls help me out. Thx Vidh