tags:

views:

194

answers:

3

Hello everybody,

I got a problem with form.Show() in C# .NET Framework 2.0.

    //segment code (FormA's caller)
    FormA frmA = new FormA();

    writeLog("Begin: " + Environment.TickCount);
    frmA.SuspendLayout();
    frmA.Show();
    frmA.ResumeLayout();
    writeLog("End: " + Environment.TickCount);

    ....



    //segment code (FormA)
    private void FormA_Load(object sender, EventArgs e){
     writeLog("Begin - Load: " + Environment.TickCount);
    }

From above segment code, I build in release mode and execute it. I found diffrent time between "Begin:" and "Begin - Load" about 2 - 3 second on my notebook (Windows XP x86), yet different time on Server (Windows 2003 SP2) is more than 5 second. I don't know why.

In addition, FormA have many TableLayout and UserControl (total controls approximate 800 )

+2  A: 

If you've profiled and optimized your form, you might have to use a wait cursor, a splash screen or a progress bar.

If you have NOT profiled, I strongly recommend you do so. There may be a few methods that eat up a lot of time.

If you have a lot of controls (800 you say?) in your form, you might consider modifying the form's initialization to use a backgroundworker - essentially you load your controls in a separate thread. This may or may not be possible, given your specific requirements.

Edit:

I assumed in my answer that your 800 controls were necessary - it's very likely that you can reorganize your code to load controls only when needed. If you're not immediately able to reorganize your code, profiling to find the worst culprits is a good second choice.

Charlie Salts
A: 

I think profiling the form might not be what you need, but rather profiling the user controls.

Or even better. If you have tabs in you form, maybe you can move the loading of controls to when a tab is fiven the focus for the first time. Only load tose cotrols that will be visible to the user on startup, then load the rest on request.

astander
+1  A: 

Profile your initialize component method. Do you have non native controls? Third party ones? Some of them are notoriously slow to render. Are you setting the datasource for any of the controls? Populating a control with items at design time? Try to move them after your page load.

And yes, 800 controls is a page. That's just a badly designed page. Fix that first.

Bobby Alexander
Yes, I have my controls and some control use for show TIFF image
Fuangwith S.
+1 Yeah, 800 is huge. I'm hoping though, that the OP will realize that after profiling.
Charlie Salts