Click here to Skip to main content
15,897,315 members
Home / Discussions / C#
   

C#

 
QuestionHow to handle the event of killing a process from task manager??? Pin
Bins Davis13-Jun-08 1:24
Bins Davis13-Jun-08 1:24 
AnswerRe: How to handle the event of killing a process from task manager??? Pin
Simon P Stevens13-Jun-08 3:15
Simon P Stevens13-Jun-08 3:15 
Handle the Application.ApplicationExit event.

Note that this will only get triggered if the user uses the "End Task" button on the Applications tab. The "End Process" button on the Processes tab will not trigger this event.

This is because EndTask allows the app to run any clean up code itself. EndProcess is to kill totally unresponsive processes. You can't get round this. You have to accept that the user always has overall control of their PC and if they want to kill your app without letting it clean up they can. Windows does warn that killing processes can cause undesired behaviour. (Just think, the user could just pull the plug out from the socket which would give your app no time to clean up)

I would suggest writing the data out periodically (say every 10 minutes) and save a timestamp with the data so you know when it was saved. Then, when the service is exited correctly, write out a little bit of information at the end of the file that says "Service exited correctly" or something that means that. Then, when your service starts up, look for the "Service exited correctly" message. If it's not there you know the service was terminated unexpectedly, so you can warn the user. If you stored a timestamp with the saved data you can tell the user how much data was lost etc.

Simon

GeneralRe: How to handle the event of killing a process from task manager??? Pin
Bins Davis15-Jun-08 20:54
Bins Davis15-Jun-08 20:54 
QuestionMDI Parent won't allow Child maximise Pin
Yosh_13-Jun-08 1:14
professionalYosh_13-Jun-08 1:14 
AnswerRe: MDI Parent won't allow Child maximise Pin
DaveyM6913-Jun-08 3:45
professionalDaveyM6913-Jun-08 3:45 
QuestionProblem removing edges Pin
Gareth H13-Jun-08 0:13
Gareth H13-Jun-08 0:13 
AnswerRe: Problem removing edges Pin
Ashfield13-Jun-08 0:22
Ashfield13-Jun-08 0:22 
GeneralRe: Problem removing edges Pin
Gareth H13-Jun-08 0:28
Gareth H13-Jun-08 0:28 
GeneralRe: Problem removing edges Pin
Ashfield13-Jun-08 2:01
Ashfield13-Jun-08 2:01 
AnswerRe: Problem removing edges Pin
Simon P Stevens13-Jun-08 0:26
Simon P Stevens13-Jun-08 0:26 
GeneralRe: Problem removing edges Pin
Gareth H13-Jun-08 0:29
Gareth H13-Jun-08 0:29 
GeneralRe: Problem removing edges Pin
Simon P Stevens13-Jun-08 0:56
Simon P Stevens13-Jun-08 0:56 
Questionreading a xml document from a listview Pin
laziale12-Jun-08 23:22
laziale12-Jun-08 23:22 
AnswerRe: reading a xml document from a listview [modified] Pin
leppie12-Jun-08 23:30
leppie12-Jun-08 23:30 
AnswerRe: reading a xml document from a listview Pin
Eslam Afifi12-Jun-08 23:34
Eslam Afifi12-Jun-08 23:34 
QuestionBandwith Monitoring Pin
amilapradeep12-Jun-08 23:17
amilapradeep12-Jun-08 23:17 
AnswerRe: Bandwith Monitoring Pin
leppie12-Jun-08 23:28
leppie12-Jun-08 23:28 
GeneralRe: Bandwith Monitoring Pin
amilapradeep13-Jun-08 1:45
amilapradeep13-Jun-08 1:45 
QuestionGetting outlook items in the webpage Pin
manikandanid12-Jun-08 23:13
manikandanid12-Jun-08 23:13 
QuestionEvent issue in custom control Pin
Harvey Saayman12-Jun-08 22:56
Harvey Saayman12-Jun-08 22:56 
AnswerRe: Event issue in custom control Pin
leppie12-Jun-08 23:39
leppie12-Jun-08 23:39 
GeneralRe: Event issue in custom control Pin
Harvey Saayman13-Jun-08 0:01
Harvey Saayman13-Jun-08 0:01 
Questiondefault comparer Pin
George_George12-Jun-08 22:54
George_George12-Jun-08 22:54 
AnswerRe: default comparer Pin
Simon P Stevens12-Jun-08 23:04
Simon P Stevens12-Jun-08 23:04 
GeneralRe: default comparer Pin
George_George12-Jun-08 23:22
George_George12-Jun-08 23:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.