I have a problem with performance of my code under Windows Forms.
Have a form, her layout is depending on constructor data, because he layout must be OnLoad or in Constructor generated.
I generation is simple, base FlowLayoutPanel have other FlowLayoutPanels, for each have a Label and TextBox with DataBinding.
Problem is this is VERY SLOW, up to 20 seconds, i drawing less than 100 controls, from Performace Session i know a problem is on 70% procesing functions:
How i can do with this? Anyone help me in this problem? How solve the dynamic form layout problem?
Have you disabled layout while adding the controls?
panel.SuspendLayout();
try
{
// add controls in a loop/etc here
}
finally
{
panel.ResumeLayout();
}
I recently read the this article that has a ton of ideas for optimizing performance in .Net Winforms apps. MSDN Article
Some of those that may apply to your situation are that if you are retrieving the data that you are Databinding the Controls to you may want to spin that off onto a sep. thred from the UI so it can retrieve the Data Asynchronously.
You can do this with the Background Worker class.
Also if only some of the controls are not going to be initially visible you can postpone that work until later.
"Operations that must be performed, but are not needed for displaying the first "UI, can be done while the system is idle or on demand after the first UI is shown. "For example, if you have a TabControl, populate only the topmost page on startup "and retrieve the information for other pages when required."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With