Check if the program has thrown an exception

I am working on a health monitoring program for my company and we need to know if a process on the remote machine hangs for lack of response (which I can do), or if it raised an unhandled exception. I've tried several things, checking the CPU usage of the process to check if the process went idle. Nothing was really reliable. Is there any way to do this? All programs that we will monitor are running on .NET 3.5 or 4.0.

+3


source to share


4 answers


Thanks for the answers guys, I have a decent job for what I need:

After a little research, I found out that a .NET program starts 4 threads on startup. None of the programs I control here have opened any new threads. I also found out after some testing that the exception message opens on a new thread and causes the CPU usage for the program to drop to 0. So, I check both of these conditions:



if CPU = 0 and threadCount > 4

      

Most likely an exception was thrown. Because why else sit there a program with 0 CPU and more than 4 threads? As far as I can see now, there is no other reason.

+1


source


The answer will be much easier if you have control over the source of these applications.

The way we handle this scenario is that the applications being checked periodically write their status to a central database. The monitoring application then checks the status in these tables on a regular basis and if the status is not updated within a certain period of time (i.e. 2 minutes), alerts are generated.



This helps us identify not only application problems, but also connection problems and unexpected computer restarts.

+1


source


Would checking the event log (system / security) help you with the event source as a process that you control?

+1


source


You can try to track the event log on the system where this process is running. When a process throws and an exception that is unsullied, an entry is made here with the process and some details of the error.

There are a few more questions on the stack that address this same question.

catch another unhandled process exception
How to catch exceptions from processes in C #

+1


source







All Articles