WPF 和 CefSharp:性能低迷

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42549349/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 14:01:44  来源:igfitidea点击:

WPF and CefSharp: sluggish performance

c#wpfcefsharp

提问by Edwin

I have successfully made a personal mini browser app in c# winforms. Because I want some more fancy effects, I was considering to make a WPF app. So I tried the wiki tutorial and set up a simple WPF form with a browser, but noticed it has sluggish performance. It's even noticeable when selecting text in very simple webpage, or just when scrolling the page. Is there anything that can be done? If not, I guess it will be just winforms then, since that one behaves and performs well.

我已经成功地在 c# winforms 中制作了一个个人迷你浏览器应用程序。因为我想要一些更奇特的效果,所以我正在考虑制作一个 WPF 应用程序。所以我尝试了 wiki 教程并使用浏览器设置了一个简单的 WPF 表单,但注意到它的性能很慢。在非常简单的网页中选择文本时,或者只是在滚动页面时,它甚至会很明显。有什么可以做的吗?如果没有,我想那将只是 winforms,因为它的行为和性能都很好。

edit: my specs: http://users.telenet.be/dropbox/specs.html

编辑:我的规格:http: //users.telenet.be/dropbox/specs.html

回答by Evk

WPF version of cefsharp uses different model of rendering than WinForms. In WPF it basically copies each frame into bitmap and you might imagine how slow it can become. This is especially noticeable on high-resolution screens. There are some options to improve that perfomance (see herefor example), but in my experience (I tried all that options) non of them really helps to match WinForms. To run cefsharp smoothly in my WPF project I actually had to use WinForms version of cefsharp and host it inside WindowsFormsHost- this helps with perfomance problems but has it's caveats of course (for example you cannot partially hide WinForms hosted control behind WPF controls - it will always be rendered on top of everything). Still for now I consider this the only viable option, because high-resolution screens are now quite widespead.

cefsharp 的 WPF 版本使用与 WinForms 不同的渲染模型。在 WPF 中,它基本上将每一帧复制到位图中,您可能会想象它会变得多慢。这在高分辨率屏幕上尤其明显。有一些选项可以提高性能(例如参见此处),但根据我的经验(我尝试了所有这些选项),它们中没有一个真正有助于匹配 WinForms。为了在我的 WPF 项目中顺利运行 cefsharp,我实际上必须使用 WinForms 版本的 cefsharp 并将其托管在里面WindowsFormsHost- 这有助于解决性能问题,但当然有警告(例如,您不能部分隐藏 WPF 控件后面的 WinForms 托管控件 - 它始终会呈现在所有内容之上)。现在我仍然认为这是唯一可行的选择,因为高分辨率屏幕现在非常广泛。

回答by Luca Ziegler

This will disable WebGL, look at the source to determine which flags best suite your requirements. "grMain" is a Grid in Wpf

这将禁用 WebGL,查看源代码以确定哪些标志最适合您的要求。“grMain”是 Wpf 中的网格

CefSettings s = new CefSettings();
s.SetOffScreenRenderingBestPerformanceArgs();
Cef.Initialize(s);
ChromiumWebBrowser wbMain = new ChromiumWebBrowser();
grMain.Children.Add(wbMain);