如何以编程方式检查应用程序是否已挂起在VB.NET中

Den*_*nis 5 vb.net monitoring watchdog hang

我需要编写一个监视/监视程序来检查一系列应用程序

监测计划应该能够

  1. 确定它正在监视的应用程序是挂起还是没有响应
  2. 如果它挂起,请重新启动特定应用程序

VB.NET中的哪种API可以帮助我实现这一目标?

任何代码示例都会非常有用

Edd*_*Paz 5

您可以使用System.Diagnostics.Process来启动/查找您正在观看的进程.根据您正在观看的应用,您可以使用以下内容:

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
Run Code Online (Sandbox Code Playgroud)

确定应用程序是否"挂起"并不总是很清楚.它可能只是忙着做某事.Process.Responding还需要一个MainWindow.

这是一个非常简单的例子,但我希望它能指出你正确的方向.