开发者

WinForms ElementHost slows down with repeated use

开发者 https://www.devze.com 2023-02-27 13:32 出处:网络
I have a scenario where using WPF as part of a modeless dialog drastically out-performs the alternatives.However, what I\'m seeing is that each time I bring up the dialog, it gets a little slower, unt

I have a scenario where using WPF as part of a modeless dialog drastically out-performs the alternatives. However, what I'm seeing is that each time I bring up the dialog, it gets a little slower, until eventually it takes up to 20 seconds to bring the dialog up.

I profiled it with ANTS and it basically points开发者_Go百科 to ElementHost in three different places during the InitializeComponent portion of my form: Creation of the host, setting the background color (which I can eliminate), and assigning the child.

While this is happening on a separate UI thread from the main UI thread (done by creating a thread, setting it's apartment to STA, then executing another Application.Run(myform) within) it still locks up the main GUI due to it being extremely busy.

If you kill the app and start over, the problem goes away and it performs very well again for a while. No other portion of the code seems to slow down.

Is there something I can do to clean up after ElementHost?


I found out the What, but not the Why.

I have to manually dispose of the ElementHost when the form is disposed of, otherwise it leaves the WPF elements intact. Those build up over time and slow things down.

0

精彩评论

暂无评论...
验证码 换一张
取 消