Search code examples
c#winformswebbrowser-controlawesomium.net-4.6.1

Awesomium Web Browser - How WebCore.Shutdown & WebCore.Initialize Again


I am using Awesomium as a web browser control in my winform application.
In a button's click event i want to Shutdown & ReInitialize WebCore.
How can i do this job?
I wrote these codes, but i got the error below :

Codes :

webBrowser_main.Dispose(); <------> I want to remove this previous awesomium control & recreate it again with same ID
WebCore.Shutdown();

await dl(5000, 7000);

WebConfig config = new WebConfig() { UserAgent = "blablabla", LogLevel = LogLevel.None };
WebCore.Initialize(config); <------> I HAVE ERROR HERE
WebCore.Initialized += WebCoreInitialzed;
WebCore.Download += WebCoreDownload;

WebControl browser = new WebControl();
browser.Name = "webBrowser_main";
browser.BackColor = System.Drawing.Color.GreenYellow;
browser.Location = new System.Drawing.Point(12, 29);
browser.Size = new System.Drawing.Size(960, 565);
browser.TabIndex = 52;
browser.ViewType = Awesomium.Core.WebViewType.Offscreen;
browser.ShowJavascriptDialog += new Awesomium.Core.JavascriptDialogEventHandler(webBrowser_main_ShowJavascriptDialog);
browser.TargetURLChanged += new Awesomium.Core.UrlEventHandler(webBrowser_main_TargetURLChanged);
browser.ShowCreatedWebView += new Awesomium.Core.ShowCreatedWebViewEventHandler(webBrowser_main_ShowCreatedWebView);
browser.DocumentReady += new Awesomium.Core.DocumentReadyEventHandler(webBrowser_main_DocumentReady);
browser.LoadingFrame += new Awesomium.Core.LoadingFrameEventHandler(webBrowser_main_LoadingFrame);
browser.LoadingFrameComplete += new Awesomium.Core.FrameEventHandler(webBrowser_main_LoadingFrameComplete);
browser.MouseMove += new System.Windows.Forms.MouseEventHandler(webBrowser_main_MouseMove);
browser.Source = new System.Uri("https://www.google.com", System.UriKind.Absolute);
browser.TabIndex = 0;
this.Controls.Add(browser);

And here is the error :

An exception of type 'System.InvalidOperationException' occurred in Awesomium.Core.dll but was not handled in user code

Additional information: You are attempting to re-initialize the WebCore. The WebCore must only be initialized once per process and must be shut down only when the process exits.


Solution

  • For now Chromium does not support "re-initialization" after Shutdown() method was called. So, libraries based on it (Awesomium, CEF etc) do not support such functionality as well.

    Depending on why do you need this functionality, you can try something else (e.g. clear cache, cookies).