开发者

is there an equivalent to trace=true in Winforms?

I have a winform that is taking too long to load. The form has a gazillion of controls and I would like to see how much time each control takes to load. If it were a web app, I would have just turned the trace on, but I can not find anything simila开发者_开发知识库r in winforms.

Any thoughts?

Thanks.


It is pretty unlikely that it is actually the loading that's slow. The constructor is usually fast, regardless of how many controls you create. If you have a Load event handler, you can easily measure how long it takes with the Stopwatch class or a profiler.

No, the most common reason for perceived slowness in forms with a lot of controls is simply the long time it takes to paint the controls. That happens pretty quickly, you start noticing with 50 controls. Which is about as many child windows as Microsoft Outlook uses. The time it takes for each control to paint itself is pretty predictable. The more intricate its look, the longer it takes. A simple test you can do is watching how long it takes when you minimize, then restore the form. If that's slow too then it is painting that's the bottleneck.

Nothing much you can do to make this magically faster. Other than just using less controls. A Label for example is particularly expensive for the job it does, you can replace it with a line of code in the OnPaint method. Component vendors like Telerik specialize in selling controls that don't use a window.


May be a related question could help you with tracing/logging in WinForms: How do I create an automatic UI event trace in winforms?

Also you may look at this: Writing trace information in a windows form app

Hope it helps!


My guess is there's a few that take the longest time to load because they have to connect to a remote server.

Try disabling the most likely suspects and see if that improves your performance. It should. Then, enable each of the remote controls one at a time to see if it's visibly obvious which control is slowing everything down.

It may not be. There may be 6 controls that each take 5 seconds to load. I doubt you need precise tracing info, just an understanding of which controls are the worst performance-killers.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜