在线急等,寻求多线程下的解决办法。
以下为我的程序里的部分代码:
此部分代码启动IE进程,当单线程的情况下,没有任何问题,发现线程只要是达到2个以上就或多或少程序报错,并且线程数目越高报错机率越大。我检查发现是多线程情况下,无法绑定该线程启动的IE进程,请教线程如何判断哪个IE进程是它启动的。
Dim startInfo As New ProcessStartInfo("IExplore.exe")
startInfo.WindowStyle = ProcessWindowStyle.Maximized
startInfo.Arguments = url
Dim p As New Process
p.Start(startInfo)
'Process.Start(startInfo)
Dim allBrowsers As SHDocVw.ShellWindows = New SHDocVw.ShellWindows
Dim ie As InternetExplorer
'Exit Sub
myProcesses = Process.GetProcesses()
Threading.Thread.Sleep(5000)
'MsgBox(myProcesses.Count)
Dim i As Integer = 0
While i < allBrowsers.Count
Dim ev As InternetExplorer = DirectCast(allBrowsers.Item(i), InternetExplorer)
MsgBox(ev.LocationURL)
Try
If InStr(allBrowsers.Item(i).LocationURL, url) <> -1 Then
ie = DirectCast(allBrowsers.Item(i), InternetExplorer)
End If
Catch ex As Exception
'MsgBox(ex.Message)
End Try
i += 1
End While