List Info

Thread: Best way to run pre-form load code on startup




Best way to run pre-form load code on startup
user name
2006-03-29 18:28:43
From:    Kelly Baker <kbakerHOWARD-IND.COM>

>In VB6, I could set the startup code to be Sub Main in a
module.
>In Sub Main, I would always initialize a lot of my
hardware
>(industrial equipment and I/O) before loading the first
form.  I
>would also explicitly instantiate the form objects and
set the
>object to Nothing when I was done with the form.  I
don't see
>the parallel in .Net.  I know forms are still objects,
but how do
>instantiate the first one if I can't have a Sub Main?

Several people have answered this directly, but I want to
look
at it in a different way.

That sounds like a rather time-consuming initialization.

We've learned around here that one way to make an
application
feel slow and unresponsive, is to do time-consuming
initialization
before showing a form.

But we don't WANT the application to feel slow and
unresponsive.

So - we WANT to show the form first, and then do
initialization.

That doesn't mean that we do initialization in form_load.
The
form isn't showing yet.

It means we put a timer on the form. In form-load, we start
the timer with a very short interval. And when the timer
fires,
THEN we turn off the timer and do initialization.

And if the initialization is REALLY time consuming, and the
user can't
actually do anything yet, we try to visibly change the form
from
time to time in the process.

Now this first form might be just a splash screen. Maybe at
the
end of initialization we open the second form and then hide
- or
close - the first.

However, we'd prefer to have that first form be usable, and
have initialization finish in the background - hopefully
before the
user tries to use something we're initializing.

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )