Note: Advice in this article will only work for DotNetBrowser 1.
See the corresponding article for DotNetBrowser 2 here.
Each Browser
instance is running on a separate native process where the web page is rendered. Sometimes this process can exit unexpectedly because of the crash in plugin. To receive notifications about unexpected render process termination you can use RenderListener
. When you receive notification about render process termination you can display a "sad" icon like Google Chrome does, for example, to inform the user that this particular Browser
component has crashed.
If you refresh or load the same or another URL, the rendering process and Browser
instance will be restored:
C#
using DotNetBrowser; using DotNetBrowser.Events; using DotNetBrowser.WPF; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace RestoreBrowserSample { /// <summary> /// This sample demonstrates how to restore Browser instance after its /// native process unexpectedly terminated. In general to rest Browser owser instance you just need to load the same or another URL. /// </summary> class Program { public class WindowMain : Window { public WPFBrowserView browserView; public WindowMain() { BrowserContext browserContext = BrowserContext.DefaultContext; Browser browser = BrowserFactory.Create(browserContext); browser.RenderGoneEvent += delegate(object sender, RenderEventArgs e) { // Restore Browser instance by loading the same URL browser.LoadURL(e.Browser.URL); }; browserView = new WPFBrowserView(browser); Content = browserView; Width = 1024; Height = 768; this.Loaded += WindowMain_Loaded; } void WindowMain_Loaded(object sender, RoutedEventArgs e) { browserView.Browser.LoadURL("http://www.google.com"); Console.Out.WriteLine("Run 'Task Manager' app and kill the 'browsercore32.exe' " + "process with the '--type=renderer' command line argument."); } [STAThread] public static void Main() { Application app = new Application(); WindowMain wnd = new WindowMain(); app.Run(wnd); var browser = wnd.browserView.Browser; wnd.browserView.Dispose(); browser.Dispose(); } } } }
VB.NET
Imports System.Windows Imports DotNetBrowser Imports DotNetBrowser.Events Imports DotNetBrowser.WPF ''' <summary> ''' This sample demonstrates how to restore Browser instance after its ''' native process unexpectedly terminated. In general to reset the Browser owner instance you just need to load the same or another URL. ''' </summary> Public Class WindowMain Inherits Window Public Dim browserView As WPFBrowserView Sub New() Dim browserContext As BrowserContext = BrowserContext.DefaultContext Dim browser As Browser = BrowserFactory.Create(browserContext) AddHandler browser.RenderGoneEvent, Sub(sender As Object, e As RenderEventArgs) ' Restore Browser instance by loading the same URL browser.LoadURL(e.Browser.URL) End Sub browserView = New WPFBrowserView(browser) Content = browserView Width = 1024 Height = 768 AddHandler Loaded, AddressOf WindowMain_Loaded End Sub Private Sub WindowMain_Loaded(sender As Object, e As RoutedEventArgs) browserView.Browser.LoadURL("http://www.google.com") Console.Out.WriteLine("Run 'Task Manager' app and kill the 'browsercore32.exe' " + "process with the '--type=renderer' command line argument.") End Sub End Class Module Module1 <STAThread> Sub Main() Dim app As Application = New Application() Dim wnd As WindowMain = New WindowMain() app.Run(wnd) Dim browser = wnd.browserView.Browser wnd.browserView.Dispose() browser.Dispose() End Sub End Module