I was able to solve this problem as follows:
At the moment I need to bring the browser to the homepage,
WebBrowser1.Navigate (home page) , I did the following ... When I try to go to the home page and the browser is locked with the active alert, I apply the .Dispose () / strong> in the object, and I still define it as = nothing .
After that I create a WebBrowser again as the same characteristics, however it will have a different nine so I used a Random () to generate a randomly named object.
As my application only has a WebBrowser, all the places where I make a request of my WebBrowser I need to use a code that searches the object for CType (), since I do not know the name of the new WebBrowsers that will be created. br>
So the code looks like this:
//Tenta redirecionar para página inicial
Try
//Procura o WebBrowser ativo
For Each ctrlsweb In Me.Controls
If (ctrlsweb.GetType() Is GetType(WebBrowser)) Then
Dim browserc As WebBrowser = CType(ctrlsweb, WebBrowser)
//Aqui você executa as ações para esse webbrowser que o codigo transformou em variável
browserc.Navigate(pagInicial)
End If
Next
//Se houver algum erro, então e
Catch ex As Exception
//Elimina o objeto Browser ativo
For Each ctrlsweb In Me.Controls
If (ctrlsweb.GetType() Is GetType(WebBrowser)) Then
Dim browserc As WebBrowser = CType(ctrlsweb, WebBrowser)
browserc.Focus()
SendKeys.Send("{ENTER}")
browserc.Dispose()
browserc = Nothing
End If
Next
//Gera um número randomico para usar no nome do objeto Browser
Dim geraRand As Random = New Random()
Dim numero As String = geraRand.Next(1013, 8939)
//Cria novo WebBrowser
Dim web As New WebBrowser
web.Name = "WebBrowser" & numero
web.Dock = DockStyle.Fill
web.ScriptErrorsSuppressed = True
End Try
If your WebBrowser has Handler actions like mine, for example DocumentCompleted , Navigating , etc ... you can use this code after creating the WebBrowser: br>
AddHandler web.Navigating, Sub()
BarStatus.Text = "Carregando..."
StatusOK.Visible = True
//Mais código aqui...
End Sub