2016-08-19 56 views
0

所以我想要做的是能夠以同樣的形式在2個cefsharp瀏覽器窗口中同時加載2個網址 此示例圖像將有助於解釋一點更好 enter image description here在不同的實例中同時加載2個URL:CefSharp

我似乎無法弄清楚如何做到這一點。目前我只能看到一個例子。如果我嘗試運行2我得到這個錯誤:

An unhandled exception of type 'System.Exception' occurred in CefSharp.Core.dll 

Additional information: Cef can only be initialized once. Use Cef.IsInitialized to guard against this exception. 

如果不能做到能有人爲推薦另一HTML5支持C#瀏覽器嗎?

public ChromiumWebBrowser Browser; 
CefSettings settings = new CefSettings(); 
    void InitBrowser() 
     { 
      settings.UserAgent = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2764.0 Safari/537.36"; 
      Cef.Initialize(settings); 
      Browser = new ChromiumWebBrowser("about:blank"); 
      Browser.FrameLoadEnd += OnFrameLoadEnd; 
      Browser.LoadingStateChanged += OnLoadingStateChanged; 
      Browser.FrameLoadStart += OnFrameLoadStart; 
      Browser.LoadError += OnLoadError; 
      Controls.Add(Browser); 
      Browser.Dock = DockStyle.Fill; 
     } 
+0

https://github.com/cefsharp/CefSharp.MinimalExample/blob/master/CefSharp.MinimalExample.WinForms/Program.cs#L16簡單的選項是在'Program.cs'中初始化。 – amaitland

回答

0

只能初始化一次CEF,每個應用程序。

github CefSharp repository here甚至有一個話題。

You can only initialize CEF once, per application. Nothing has changed in regards to this. It's just how CEF functions.

Although the architecture of CEF and CefSharp (which is merely a .NET binding on top of it) is different: https://bitbucket.org/chromiumembedded/cef/wiki/Architecture#markdown-header-process-considerations . There is a one common Browser process which then spawn a Renderer process for each "window" or "tab". (You can see them in your Windows Task Manager)

基本上這是不可能的,甚至在不同的形式。

您可以檢查是否有已經使用了下面的代碼片斷運行的任何實例(也許你可以停止,然後再開始另一個,雖然你的情況,似乎是無用的):

if (Cef.IsInitialized) 
{ 
    Console.WriteLine("Sorry, cannot start other instance because there's already an open browser"); 
} 
-1

您可能運行使用System.Threading

「你只能初始化CEF一次,每個應用程序」從這我明白;您可以使用Run.Application(new Form())多次,使用System.Threading

相關問題