Under task manager, if the application freezes, it says not responding. Is there a way or an API that can detect which process name that is not responding?
Printable View
Under task manager, if the application freezes, it says not responding. Is there a way or an API that can detect which process name that is not responding?
Read this article http://support.microsoft.com/kb/304991, it is use C# but it is simple enough to convert to VB.
Not sure if posts #12 and #13 here will be of use or not?
You could also try the IsHungAppWindow function.
Thanks, all. Is there a way to force the IE to stop responding so that I can test whether or not the code works?
You can use SuspendThread.
That is c++, is there a vb one?
Here are the VB declares for the abovementioned APIs:
Code:Private Declare Function IsHungAppWindow Lib "user32.dll" (ByVal hWnd As Long) As Long
Private Declare Function SuspendThread Lib "kernel32.dll" (ByVal hThread As Long) As Long
Thanks Bonnie, I'll try that. Does anyone know how to convert this to vb? It's from this site.
http://support.microsoft.com/kb/304991
Code:procs = Process.GetProcessesByName("IEXPLORE");
Bonnie, how do I get the thread handle of an application?
Here is an auto converted of the code at http://support.microsoft.com/kb/304991
Code:Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports SHDocVw
Imports System.Diagnostics
Namespace appStoppedresponding_cs
Public Class Form1
Inherits System.Windows.Forms.Form
Private WithEvents btnStart As System.Windows.Forms.Button
Private WithEvents btnCheck As System.Windows.Forms.Button
Private WithEvents btnClose As System.Windows.Forms.Button
Private components As System.ComponentModel.Container = Nothing
Private Browser As InternetExplorer
Protected procs() As Process
Public Sub New()
InitializeComponent()
End Sub
Protected Overrides Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If components IsNot Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
#Region "Windows Form Designer generated code"
Private Sub InitializeComponent()
Me.btnCheck = New System.Windows.Forms.Button()
Me.btnStart = New System.Windows.Forms.Button()
Me.btnClose = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
' btnCheck
'
Me.btnCheck.Location = New System.Drawing.Point(66, 122)
Me.btnCheck.Name = "btnCheck"
Me.btnCheck.Size = New System.Drawing.Size(152, 23)
Me.btnCheck.TabIndex = 1
Me.btnCheck.Text = "Check Internet Explorer"
' Me.btnCheck.Click += New System.EventHandler(Me.btnCheck_Click)
'
' btnStart
'
Me.btnStart.Location = New System.Drawing.Point(66, 74)
Me.btnStart.Name = "btnStart"
Me.btnStart.Size = New System.Drawing.Size(152, 23)
Me.btnStart.TabIndex = 0
Me.btnStart.Text = "Start Internet Explorer"
' Me.btnStart.Click += New System.EventHandler(Me.btnStart_Click)
'
' btnClose
'
Me.btnClose.Location = New System.Drawing.Point(66, 170)
Me.btnClose.Name = "btnClose"
Me.btnClose.Size = New System.Drawing.Size(152, 23)
Me.btnClose.TabIndex = 2
Me.btnClose.Text = "Close Internet Explorer"
' Me.btnClose.Click += New System.EventHandler(Me.btnClose_Click)
'
' Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.AddRange(New System.Windows.Forms.Control() { Me.btnClose, Me.btnCheck, Me.btnStart})
Me.Name = "Form1"
Me.Text = "Form1"
' Me.Closing += New System.ComponentModel.CancelEventHandler(Me.Form1_Closing)
' Me.Load += New System.EventHandler(Me.Form1_Load)
Me.ResumeLayout(False)
End Sub
#End Region
'example code
''' The main entry point for the application.
<STAThread>
Shared Sub Main()
Application.Run(New Form1())
End Sub
Private Sub btnStart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStart.Click
Browser = New InternetExplorer()
Browser.Visible = True
Browser.GoHome()
procs = Process.GetProcessesByName("IEXPLORE")
'Build event delegate to catch browser close event.
Dim oDelegate As New SHDocVw.DWebBrowserEvents2_OnQuitEventHandler(AddressOf Browser_OnQuit)
Browser.OnQuit += oDelegate
End Sub
Private Sub btnCheck_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCheck.Click
If Browser IsNot Nothing Then
If procs(0).Responding Then
MessageBox.Show("IEXPLORE is Responding")
Else
MessageBox.Show("IEXPLORE is Not Responding")
End If
Else
MessageBox.Show("IEXPLORE is Not Running")
End If
End Sub
Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.closeBrowser()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Browser IsNot Nothing Then
Me.closeBrowser()
End If
End Sub
Private Sub closeBrowser()
Try
If procs(0).Responding Then
procs(0).CloseMainWindow()
Else
procs(0).Kill()
End If
'Destroy object reference and array.
Me.cleanUp()
Catch
MessageBox.Show("Could Not Find the IEXPLORE Process")
End Try
End Sub
Private Sub Browser_OnQuit()
Me.cleanUp()
End Sub
Private Sub cleanUp()
Browser = Nothing
procs=Nothing
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
End Namespace
@4x2y,
That is .Net the op wants vb6 code.