首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >每个进程只能初始化一次CEF。这是底层的限制。

每个进程只能初始化一次CEF。这是底层的限制。
EN

Stack Overflow用户
提问于 2022-07-30 00:46:33
回答 2查看 325关注 0票数 -3

每个进程只能初始化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,必须在创建第一个实例之前。

EN

回答 2

Stack Overflow用户

发布于 2022-08-01 02:08:14

如果您意外地看到这一点,那么您可能在创建ChromiumWebBrowser实例之后调用Cef.Initialize,必须是在创建第一个实例之前。

您需要检查您的代码,以确定在何处创建了ChromiumWebBrowser实例,或者如果您自己调用了Cef.Initialize两次。您没有为其他人提供足够的代码示例来发现问题。

您是否也通过设计器添加了ChromiumWebBrowser实例?

一个可能的解决方案,我个人的偏好是在创建第一个表单之前在Program.Main中调用Program.Main,这大大简化了所需的逻辑。

代码语言:javascript
复制
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;
        }
    }
}
票数 0
EN

Stack Overflow用户

发布于 2022-11-14 18:13:23

代码语言:javascript
复制
     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);
票数 -4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73172139

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档