2

I have a program which uses many hidden GUI components. For example, all the menu items, and the printer dialogs/components (which take up at least 50ms alone). In total, I'm guessing around 300ms (or 40%) of the startup of the whole program is thanks to all the hidden stuff.

What I would love to do is create these after the main immediately visible GUI is drawn (similar advice was mentioned in this thread). However, the Visual Studio editor will obviously revert it back to 'normal' after I add/change elements in the GUI designer, and keep creation of all the GUI widgets back together again in the InitializeComponent() function.

Is it possible to achieve what I want, perhaps by cordoning off particular GUI widgets which Visual Studio isn't allowed to 'touch', whilst leaving the rest for VS to play with? This way, I'd get full performance without sacrificing the convenience of the GUI designer. Or maybe there's a better way?

Community
  • 1
  • 1
Dan W
  • 3,520
  • 7
  • 42
  • 69
  • Will this article do the trick? http://stackoverflow.com/questions/835100/winforms-suspendlayout-resumelayout-is-not-enough – Josh Dec 01 '11 at 20:29
  • It doesn't make much sense that hidden controls take that long to be constructed. Try running ngen.exe on your program, at least you can eliminate the jitter as the cause of the delay. – Hans Passant Dec 01 '11 at 21:40
  • Hi Josh, I don't think that answers my specific point, but it does seem interesting anyway, so I'll look into it. Hi Hans, I'm reluctant to use ngen, A: because of lack of protecting my program, but also B: because of maintenance and other issues I've heard about. – Dan W Dec 02 '11 at 07:37

1 Answers1

2

You'd probably be better off taking the controls you don't need immediately, and moving them out onto one or more UserControls.

You'll have to do a bit of work to move your codebehind to the new classes, but you would have had to do some work anyway to deal with some of the fields being null until you finished loading.

Joe White
  • 94,807
  • 60
  • 220
  • 330
  • Thanks. Do you think your answer would be preferable to going all-out and scrapping the convenience of the GUI designer? That's something I'm considering now that most of the GUI is in place. It's a scary thought, but maybe not as bad as I think it will be... – Dan W Dec 02 '11 at 07:34
  • 1
    I'd hesitate to abandon the designer *altogether,* since it's about guaranteed that you'll have to make some change sooner or later. But if you break your UI down into small pieces (via UserControls), then doing the window all in code -- just sticking those small pieces together -- probably wouldn't be too bad. – Joe White Dec 02 '11 at 13:14