简体   繁体   English

Mono C#WinForms - >在Mac OSX上运行时出现严重的性能问题

[英]Mono C# WinForms -> Serious performance problems when running on Mac OSX

I have a question regarding C#, Mono and OSX. 我有一个关于C#,Mono和OSX的问题。 I have created a Program in C# using Windows Forms and am trying to make it usable on a Mac. 我使用Windows Forms在C#中创建了一个程序,并尝试在Mac上使用它。

Problem is, that the performance is extremely poor on OSX and I just can´t find a way to speed it up. 问题是,OSX上的性能极差,我无法找到加快速度的方法。 The program itself is quite simple actually: A Client Server System using just two DataGridViews, a few ComboBoxes and Buttons, a TabControl, a few SplitContainers - and thats it! 该程序本身非常简单:一个客户端服务器系统只使用两个DataGridViews,一些ComboBoxes和Buttons,一个TabControl,一些SplitContainers - 就是这样! Works fine on Windows and has no speed problems whatsoever. 在Windows上运行良好,没有任何速度问题。

When I open the program on a Mac (MacBook Air, OSX Version 10.8.3) it takes ages to load the GUI. 当我在Mac上打开程序(MacBook Air,OSX版本10.8.3)时,加载GUI需要很长时间。 Building it up takes about 0.5sec on WIndows and nearly a Minute on a Mac(!). 在WIndows上构建它需要大约0.5秒,在Mac上大约需要一分钟(!)。 All the controls are built up very slow and most of the time when interacting with the program by clicking on something it takes another minimum of 10secs to respond. 所有控件的构建都非常缓慢,并且大部分时间通过点击某些内容与程序进行交互,需要至少10秒来响应。

I´ve learned that Mono natively builds up the GUI using Windows.System.Drawing. 我了解到Mono使用Windows.System.Drawing本地构建GUI。 Is that a possible reason for the extremely slow response of the program? 这可能是该计划反应极其缓慢的原因吗? What can I do to speed up the programm? 我该怎么做才能加快程序的速度? There must be some way, as Mono would be fairly useless if it´s not even usable for such a simple program... 必须有某种方式,因为如果它甚至不能用于这样一个简单的程序,Mono将毫无用处......

I have spent hours trying to google an answer to my issue and just can´t find anything usefull: AheadOfTime-Compiling, LLVM - nothing improves the performance. 我花了几个小时试图谷歌回答我的问题,但却找不到任何有用的东西:AheadOfTime-Compiling,LLVM - 没有什么能提高性能。

Thanks a lot for your answers in advance! 非常感谢你的答案!

Chris 克里斯

UPDATE: I´ve decreased the perfomance issue a bit now. 更新:我现在已经减少了性能问题。 Mono seems to have problems with the CellFormating of Gridviews. Mono似乎遇到了Gridview的CellFormating问题。 I changed the code in the applicable parts and it´s running faster now. 我更改了适用部分中的代码,现在运行得更快。

Nevertheless it still takes ages to build up the GUI. 然而,构建GUI仍需要很长时间。 You can literally watch it build the GUI. 你可以从字面上看它构建GUI。 Any suggestions on that? 有什么建议吗?

The loading time is likely the JIT compiling your code for the first time (takes my assemblies about 30-60 seconds to boot up the first time too); 加载时间可能是JIT第一次编译代码(第一次启动我的程序集大约30-60秒); running your program a second time should load much faster. 第二次运行你的程序应该加载更快。 On Windows, Visual Studio will AOT your assembly as part of the compilation, so the first boot up is fast. 在Windows上,Visual Studio会将您的程序集作为编译的一部分,因此第一次启动很快。 The slow control performance I believe is due to the font-rendering (it's not even good looking rendering either). 我认为慢控制性能是由于字体渲染(它甚至看起来都不好看)。 On top of that, keyboard handling is wrongly implemented and since Mountain Lion, you'll also need users to download XQuartz. 最重要的是, 键盘处理被错误地实现 ,自Mountain Lion以来,您还需要用户下载XQuartz。

Mono is useful, but its WinForms implementation isn't. Mono很有用,但它的WinForms实现却不是。 If OS X support is important to you, your options are as follows: 如果OS X支持对您很重要,您的选项如下:

  1. Use a different toolkit (GTK#, WX.Net, etc). 使用不同的工具包(GTK#,WX.Net等)。
  2. Build a Cocoa Library DLL using XCode and PInvoke it from C#. 使用XCode构建Cocoa Library DLL并从C#中对其进行PInvoke

The safest bet is the latter, but if your needs are simple, it might be easier to just use a different toolkit. 最安全的选择是后者,但如果您的需求很简单,那么使用不同的工具包可能会更容易。

You will have to debug on a Mac or Linux to find what exactly is running so poorly. 您将不得不在Mac或Linux上进行调试,以确定运行得如此糟糕。 Mono has some implementations that are surprisingly slow. Mono的一些实现速度非常慢。 While you see the symptom of slow UI, the cause may be something else entirely. 当您看到UI缓慢的症状时,原因可能完全不同。

For example, in a similar situation, I found that XmlDocument was very slow because I was researching why the UI was so sluggish. 例如,在类似的情况下,我发现XmlDocument非常慢,因为我正在研究UI为何如此缓慢。 If you are using XmlDocument to store the data from the server, it could cause your UI to be slow and barely responsive. 如果您使用XmlDocument存储来自服务器的数据,则可能会导致UI速度缓慢且几乎没有响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM