Tuesday, December 06, 2005

"How To Detect If an Application Has Stopped Responding by Using Visual Basic .NET"

How To Detect If an Application Has Stopped Responding by Using Visual Basic .NET

"In some situations, you may want to detect if an application is blocked. For example, when you are automating Microsoft Internet Explorer, you may want to know if Internet Explorer has stopped responding.

This article describes how to detect whether an automated instance of Internet Explorer has stopped responding (hung) and how to close Internet Explorer. Although the code is written for Internet Explorer and Visual Basic .NET, you can use this approach for other applications as well.

...

procs = Process.GetProcessesByName("IEXPLORE")
...
Try
If procs(0).Responding = True Then
MessageBox.Show("IEXPLORE is responding")
Else
MessageBox.Show("IEXPLORE is not responding")
End If
Catch
MessageBox.Show("IEXPLORE is not running")
End Try
...
Try
If procs(0).Responding Then
procs(0).CloseMainWindow()
Else
'Force closure.
procs(0).Kill()
End If

Catch notRunning As Exception When Err.Number = 91
MessageBox.Show("Could Not Find the IEXPLORE Process")

End Try

..."

Nice... I dig the .Net Framework. It just makes some things sooooo much easier.

(via Braulio Díez Botella - How to detect if a process is not responding)

2 comments:

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

Thanks for the tip. I was looking for C# code, but the conversion is trivial.