Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
591 views
in Technique[技术] by (71.8m points)

exit - Detect End Process From Task Manager In C#

I have an application in C#, and would like to monitor its current status, i.e. whether its running or closed. So far i am able to track the status if the application exits during a run time error, or any other in application exit codes.

But i am unable to log the application status when it is force closed by task manager.

Is there a way to monitor End Process events? or do i have to design a separate service to keep a watch on my application (which i find would be a waste of resources)?

Brief History: The application is a WCF subscriber Application that is meant to run as a background process and receive data from the server. I don't want to use a windows service as i am designing a GUI which allows the clients to send requests to the server for specif data.

This application is linked to another application which keeps track of the subscriber whether, the subscriber is online or offline.

Thus was looking for a way to track abrupt application close and notify the users accordingly.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm sure I have seen a question like this on SO before, so this is probably a duplicate, but I cannot find it, so...

Here is a short wrapup:

  • If you select a process in "Processes" tab and click "End Process" the process is being killed using TerminateProcess() - there is no way you can even intercept that from your process, let alone, prevent it.

  • If you select an "application" from the "Applications" tag and click "End Task", what happens depends on the type of application:

    • Console Applications are being send a CTRL_CLOSE_EVENT event.
    • Windows/GUI Applications are being send a WM_CLOSE message.

    You could respond (or handle with logging, etc.) both.

Update: Just fond the source again.

Update 2: found a/the duplicate and voting to close. I leave this answer here for now.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...