每个进程只能初始化https://i.stack.imgur.com/0SKca.png CEF一次。这是基本CEF/铬框架的一个限制。您可以通过RequestContext.SetPreference在运行时更改许多(并非全部)设置。请参见https://github.com/cefsharp/CefSharp/wiki/General-Usage#request-context-browser-isolation使用Cef.IsInitialized来防范此异常。如果您意外地看到了这一点,那么您可能在创建Cef.Initialize实例之后调用ChromiumWebBrowser,必须在创建第一个实例之前。
发布于 2022-08-01 02:08:14
如果您意外地看到这一点,那么您可能在创建ChromiumWebBrowser实例之后调用Cef.Initialize,必须是在创建第一个实例之前。
您需要检查您的代码,以确定在何处创建了ChromiumWebBrowser实例,或者如果您自己调用了Cef.Initialize两次。您没有为其他人提供足够的代码示例来发现问题。
您是否也通过设计器添加了ChromiumWebBrowser实例?
一个可能的解决方案,我个人的偏好是在创建第一个表单之前在Program.Main中调用Program.Main,这大大简化了所需的逻辑。
namespace CefSharp.MinimalExample.WinForms
{
public static class Program
{
[STAThread]
public static int Main(string[] args)
{
// Programmatically enable DPI Aweness
// Can also be done via app.manifest or app.config
// https://github.com/cefsharp/CefSharp/wiki/General-Usage#high-dpi-displayssupport
// If set via app.manifest this call will have no effect.
Cef.EnableHighDPISupport();
var settings = new CefSettings()
{
//By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache")
};
Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);
var browser = new BrowserForm();
Application.Run(browser);
return 0;
}
}
}
发布于 2022-11-14 18:13:23
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
CefSettings settings = new CefSettings();
settings.Locale = "tr";
settings.CefCommandLineArgs.Add("ppapi-flash-path", "pepflashplayer.dll");
settings.CefCommandLineArgs.Add("ppapi-flash-version", "99.0.0.999");
settings.CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Demon Slayer 3");
Cef.Initialize(settings);
Form2 frm = new Form2();
frm.Tabs.Add(new EasyTabs.TitleBarTab(frm)
{
Content = new Form1
{
Text = "Yeni Sekme"
}
}
);
frm.SelectedTabIndex= 0;
TitleBarTabsApplicationContext applicationContext= new TitleBarTabsApplicationContext();
applicationContext.Start(frm);
Application.Run(applicationContext);
https://stackoverflow.com/questions/73172139
复制相似问题