Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Simple C# Watchdog

0.00/5 (No votes)
20 Dec 2015 1  
This tip will describe the use of a simple watchdog process to monitor and revive another application.

Introduction

The watchdog process monitors and revives another application, should there be a failure. This can be used as a simple recovery technique to ensure application availability in critical environments. The WatchdogLib contains all the necessary utilities to implement and integrate a simple watchdog to your .NET applications.

Background

This post is about implementing a simple Watchdog application to revive another application. I was responsible for a mission-critical application that should run on a Windows POS device and I had to ensure the availability of that application throughout the operation time. For this, a Watchdog application was introduced.

A simple Watchdog application monitors another application process periodically and revives the monitored application if its process gets terminated due to a system failure. The monitored application should also monitor the Watchdog application and awaken it if required. Additionally, the Watchdog can be used to detect application hangs or freezes. This can be accomplished by using a heartbeat mechanism between the monitored and Watchdog applications.

Using the Code

The WatchdogLib has two main classes:

  • ApplicationWatcher (the watchdog)
  • WatchdogWatcher (the watchdog's watchdog)

Using the ApplicationWatcher

ApplicationWatcher applicationWatcher = new ApplicationWatcher("MonitoredApplication", "WatchDog", 5000);

The ApplicationWatcher class is the actual watchdog. The ApplicationWatcher constructor takes in the monitored application name, watchdog application name and the preferred monitoring interval and initiates the watchdog process.

Using the WatchdogWatcher

WatchdogWatcher watchdogWatcher = 
	new WatchdogWatcher("WatchDog", "WatchDog.exe", watchDogMonitorInterval);

The WatchdogWatcher class is integrated with the monitored application and it is responsible for observing the watchdog. The WatchdogWatcher constructor takes in the watchdog application name, watchdog executable path name and the preferred monitoring interval and initiates the watchdog watcher.

History

  • Initial version(v 1.0.0.0) of the WatchdogLib added

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here