0

My windows form has a few controls that is causing 2-3 seconds of delay after its first Form.Show() function call and before code execution Load() function is fired. All other Form.Hide() and Form.Show() functions after the first Form.Show() do not take time.

Can I initialize the form and its controls beforehand without showing it on the user so that it loads quickly on the first Form.Show() function call? I would like to initialize the form and its controls on a splash screen and then execute Form.Show() function.

I also tried Form.Hide() immediately after Form.Show() during splash screen to avoid delay in form loading afterwards on actual first Form.Show() called on user click but it shows the form for a few milliseconds on the user screen after Form.Show() call and before the Form.Hide() call which gives wrong impression.

So, I chose not to display page on user screen even for a few milliseconds to load/initialize it and its control before its first actual Form.Show() call by user.

Note: I am not exactly able to determine what is causing the delay. I put a break-point on Form.Show() function call called by a user click and on the first instruction of Form_Load() function of the form. And when I run the code, the code execution goes from Form.Show() to directly Form_Load() function of the form and this is where the delay is happening. Because the delay happens between the Form.Show() instruction call by user click to show the form, and when the code goes into Form_Load function as seen by the code execution using breakpoints.

Computer User
  • 2,839
  • 4
  • 47
  • 69
  • Are you performing some long-winded operations during load? I.e. is it the form or code you exercise _during load_ that is causing this delay? – DonBoitnott Mar 18 '14 at 14:43
  • What precise operation is causing delay? Is it instantiating the controls? – Crono Mar 18 '14 at 14:43
  • Is this your main form or a child form that spawns on user click? Not sure how you implemented the splash screen, but this link may be helpful: http://stackoverflow.com/questions/7963275/how-do-i-build-a-splash-screen-into-a-windows-forms-application-without-setting – Stinky Towel Mar 18 '14 at 14:48
  • Sorry for delay in reply. I am not exactly able to determine what is causing the delay, but the delay happens between the Form.Show() instruction call by user click to show the form, and when the code goes into Form_Load function. – Computer User Mar 18 '14 at 15:05
  • Can you post the code for your form's Load event? – Bradley Uffner Mar 18 '14 at 15:34
  • Use a profiler to diagnose perf problems. Use Ngen to fix warm start problems. Use an SSD to fix cold start problems. – Hans Passant Mar 18 '14 at 15:58
  • Use the TopLevel property when you initialize your form. If you set it to false before you call Show(), you won't see the blip by trying to Hide() it right away. Set it to true when you're ready to show your form after the splash screen. This is a hack I use when I want to initialize a form and access some things within, but not present it to the user yet. Not sure if it's *supposed* to be used this way, but it works. – B L Mar 18 '14 at 17:16

0 Answers0