Dennis
Dennis

Reputation: 3678

How to programmatically check if an application has hang in VB.NET

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

Upvotes: 5

Views: 8976

Answers (2)

CrazyTim
CrazyTim

Reputation: 7334

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

Upvotes: 1

Eddie Paz
Eddie Paz

Reputation: 2241

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.

Upvotes: 5

Related Questions