5

I need to write a monitoring/watchdog program to check a series of application

The monitoring program should be able to

  1. Determine whether the applications it is monitoring has hang or no response
  2. If it hangs, restart the specific application

What sort of API in VB.NET can help me achieve this?

any code sample would be very helpful

kaiz.net
  • 1,974
  • 3
  • 23
  • 31
Dennis
  • 2,860
  • 4
  • 23
  • 37

2 Answers2

5

You can use System.Diagnostics.Process to start/find the processes you're watching. Depending on the apps you're watching, you can use something like this:

For Each proc As Process In System.Diagnostics.Process.GetProcesses
  If proc.ProcessName = "notepad" Then
    If proc.Responding = False Then
      ' attempt to kill the process
      proc.Kill()

      ' try to start it again
      System.Diagnostics.Process.Start(proc.StartInfo)
    End If
  End If
Next

Determining if an application is "hung" is not always clear. It may just be busy doing something. Also Process.Responding requires a MainWindow.

That's a very simple example, but I hope it points you in the right direction.

Eddie Paz
  • 1,901
  • 14
  • 11
1

Roland Bär posted a good article in 2004 on codeproject.com that describes why and how to do this:

http://www.codeproject.com/Articles/8349/Observing-Applications-via-Heartbeat

CrazyTim
  • 5,106
  • 3
  • 27
  • 54