Question

Lets say I have a Windows application named app.exe, written in C# (Windows Forms), running unattended under any Windows OS (XP to 8).

I would like to monitor the status of the app:

  • Is the app still running or has it crashed
  • Has the app run into an internal error state

My idea is to set up a scheduled task in Windows (using the Task Scheduler) to run a Windows Console application, monitor.exe, every 15 minutes. The monitor app will send an email with the status of app.exe.

What I have not been able to figure out:

  • How do I find out if app.exe is still running?
  • How do I access an internal variable in app.exe from monitor.exe?

One idea was to set up a timer in app.exe which will write the internal status out to a file, and have monitor.exe read and evaluate that file every 15 minutes. But that does not appear very elegant to me (however it would work).

Do you have a better, best practise, approach?

Was it helpful?

Solution 2

Here's a more complicated solution, which you could add a monitor layer and a service layer in app.exe. The monitor layer is responsible for collecting internal variables status, and the service layer is responsible for providing internal status to whom issuing a GetStatus request.

Whenever monitor.exe is executed, it issues a GetStatus service request to app.exe, and get the response of what is going on from inside of app.exe.

The disadvantage is that you must create a connection between app.exe and monitor.exe, and the latter must know the service port of all app.exe which deployed on the local machine.

OTHER TIPS

Performance counters are perfect for this. I have several .Net applications that use a PerformanceCounterType.ElapsedTime counter and set the "last checked time" in the main loop.

I then monitor this counter with a centralized monitoring and notification system. (We use SolarWinds at work) If I expect something to run every minute and the counter exceeds 5 minutes, the alerts are set to go off.

You can send mail from app.exe in a timer for status and if you have not received mail last 15 minutes this means you app crashed or closed.

Or create try/catch for your operations for collecting informations abaut crashes and send them with e-mail that includes current status too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top