cefsharp 加载网页慢_WPF中CefSharp的AnyCPU配置

之前找了不少资料,下面是自己测试过的步骤

步骤一:添加节点CefSharpAnyCpuSupport

unload项目后可以编辑.csproj文件。或者直接用记事本编辑。

每个用到CefSharp的项目都添加。

DebugAnyCPU    ...    true

步骤二:在App.xaml.cs构造函数里添加代码

public App(){    // 当程序集的解析失败时, 从x86或x64子目录加载缺少的程序集    AppDomain.CurrentDomain.AssemblyResolve += Resolver;    // 初始化CefSharp    InitializeCefSharp();}        /// /// CefSharp初始化设置/// [MethodImpl(MethodImplOptions.NoInlining)]private static void InitializeCefSharp(){    var settings = new CefSettings();    //设置语言    settings.Locale = "zh-CN";    //禁用gpu,防止浏览器闪烁    settings.CefCommandLineArgs.Add("disable-gpu", "1");    //去掉代理,增加加载网页速度    settings.CefCommandLineArgs.Add("proxy-auto-detect", "0");    settings.CefCommandLineArgs.Add("no-proxy-serve", "1");    // 在运行时根据系统类型(32/64位),设置BrowserSubProcessPath    settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", "CefSharp.BrowserSubprocess.exe");    // 确保设置performDependencyCheck为false    CefSharp.Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);}// 尝试从x86或x64子目录加载缺少的程序集// 在使用AnyCPU运行时,CefSharp要求加载非托管依赖项private static Assembly Resolver(object sender, ResolveEventArgs args){    if (args.Name.StartsWith("CefSharp"))    {        string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";        string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", assemblyName);        return File.Exists(archSpecificPath) ? Assembly.LoadFile(archSpecificPath) : null;    }    return null;}

其他可选配置说明:修改app.config文件

  • 只需要修改启动项目下的app.config文件
  • 这段配置的意思是运行时从x86目录加载程序集,需要勾选首选32位,否则编译成64位程序会报错。
42ee249686737d41c22fad993fa54dfa.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值