Reputation: 520
The main interface to my application is moderately large. Has an outlook type schedule control. And roughly 40 .NET base controls.
If all of this is put into the form itself, it loads fast and everything looks great!
I recently moved all these controls into a User Control, and then through reflection, I load the assembly from disk and then cast it to (Control) and in my form_Load I call the following:
this.Controls.Add(myUserCtrl);
Due to moving everything into a user control, I went from a 2 - 3 second load time to a 15 - 20 second load time. Even though I am still loading the same amount of controls.
Can anyone explain why moving the controls into a UserControl would give such horrible load performance?
I have tried everything, including calling the Suspend/Resume Layout functions.
Upvotes: 2
Views: 6027
Reputation: 887797
Move your code from Form_Load
to the constructor.
In Form_Load, the controls' handles have already been created, so all updates need to make native calls to update the actual window handles.
This can be slow, depending on what you're doing. (Calling BeginUpdate
/ EndUpdate
will help somewhat)
By moving your code to the constructor, you can initialize everything before handles are created.
Depending on what your code does, this will not necessarily do any good.
Upvotes: 6