Actually, I do something like that, but I didn't want to
confuse the issue.
When my VB6 program starts, in Sub Main, I send commands to
various
hardware. Then, while I am waiting for the responses, which
trigger events
(such as a Com event in the case of an RS232 device), I
initialize and load
any forms I need to start with. This gives the impression
of a faster
startup, because the hardware initialization starts
immediately upon
execution. I plan to use background tasks to multithread
these operations
in .net, but there are still some things I would like to do
immediately upon
program start.
Thank you for your input, though. I glean tidbits of
knowledge from every
response like this.
Kelly Baker
-----Original Message-----
From: Discussion of writing applications and components
using Visual Basic
.NET [mailto:VBDOTNET DISCUSS.DEVELOP.COM] On Behalf Of Don
Edwards
Sent: Wednesday, March 29, 2006 12:29 PM
To: VBDOTNET DISCUSS.DEVELOP.COM
Subject: Re: [VBDOTNET] Best way to run pre-form load code
on startup
From: Kelly Baker <kbaker HOWARD-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(r) http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentorŪ http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
|