从WPF应用程序显示WinForm对话框的性能问题

时间:2022-04-07 19:44:19

I am currently developing a WPF application that will utilize existing WinForm dialogs. I'm experiencing a long lag between the time I call ShowDialog() on a WinForm to the time it is displayed.

我目前正在开发一个WPF应用程序,它将利用现有的WinForm对话框。我在WinForm上调用ShowDialog()到显示它的时间之间经历了很长的延迟。

Even when reusing WinForm dialog objects the lag time is nearly as bad on the second hit. Meaning that the problem isn’t in the constructor.

即使重用WinForm对话框对象,滞后时间也几乎与第二次击中时差。意味着问题不在构造函数中。

Does anybody have a work around to increase speed or know why the speed is so slow?

有没有人有办法提高速度或知道为什么速度这么慢?

1 个解决方案

#1


1  

A quick test with a blank WPF app and an empty Forms dialog on my machine indicates that the biggest delay comes from the "open window" animation that Win7 performs. So I think that there is no inherent performance problem in WPF-Forms interop. Rather, we're probably missing a crucial implementation detail about your dialog.

在我的机器上使用空白WPF应用程序和空窗体对话框进行快速测试表明最大延迟来自Win7执行的“打开窗口”动画。所以我认为WPF-Forms互操作中没有固有的性能问题。相反,我们可能错过了关于对话框的重要实现细节。

  • What is your dialog doing in Load and FormShown events? Maybe you are using inheritance and the offending code is further down in the hierarchy?
  • 你在Load和FormShown事件中做了什么对话?也许你正在使用继承而且违规代码在层次结构中更进一步?

  • Are you using a 3rd party component suite? These tend to do quite a bit of initialization on startup.
  • 您使用的是第三方组件套件吗?这些往往会在启动时进行相当多的初始化。

Your best bet probably is to use a profiler to find out where the time is actually spent.

你最好的选择可能是使用分析器来找出实际花费的时间。

#1


1  

A quick test with a blank WPF app and an empty Forms dialog on my machine indicates that the biggest delay comes from the "open window" animation that Win7 performs. So I think that there is no inherent performance problem in WPF-Forms interop. Rather, we're probably missing a crucial implementation detail about your dialog.

在我的机器上使用空白WPF应用程序和空窗体对话框进行快速测试表明最大延迟来自Win7执行的“打开窗口”动画。所以我认为WPF-Forms互操作中没有固有的性能问题。相反,我们可能错过了关于对话框的重要实现细节。

  • What is your dialog doing in Load and FormShown events? Maybe you are using inheritance and the offending code is further down in the hierarchy?
  • 你在Load和FormShown事件中做了什么对话?也许你正在使用继承而且违规代码在层次结构中更进一步?

  • Are you using a 3rd party component suite? These tend to do quite a bit of initialization on startup.
  • 您使用的是第三方组件套件吗?这些往往会在启动时进行相当多的初始化。

Your best bet probably is to use a profiler to find out where the time is actually spent.

你最好的选择可能是使用分析器来找出实际花费的时间。