Awesomium Web 浏览器 - WebCore.Shutdown & WebCore.Initialize 又如何
Awesomium Web Browser - How WebCore.Shutdown & WebCore.Initialize Again
我在我的 winform 应用程序中使用 Awesomium 作为 Web 浏览器控件。
在按钮的单击事件中,我想关闭并重新初始化 WebCore。
我该如何做这份工作?
我写了这些代码,但出现以下错误:
代码:
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);
这里是错误:
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.
目前 Chromium 在调用 Shutdown() 方法后不支持 "re-initialization"。因此,基于它的库(Awesomium、CEF 等)也不支持此类功能。
根据您需要此功能的原因,您可以尝试其他方法(例如清除缓存、cookie)。
我在我的 winform 应用程序中使用 Awesomium 作为 Web 浏览器控件。
在按钮的单击事件中,我想关闭并重新初始化 WebCore。
我该如何做这份工作?
我写了这些代码,但出现以下错误:
代码:
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);
这里是错误:
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.
目前 Chromium 在调用 Shutdown() 方法后不支持 "re-initialization"。因此,基于它的库(Awesomium、CEF 等)也不支持此类功能。
根据您需要此功能的原因,您可以尝试其他方法(例如清除缓存、cookie)。