Load Forms in background on startup

L

lsimoni

When using VB 2005 on windows CE, is it possible to load forms in the
background on application startup? I have several forms that have a bunch of
controls. The first time that the form.show is called, it takes a while to
load the form. But then if the form is hidden / shown again, it goes pretty
quickly. I would like to pre-load all of my forms on startup and then go to
my main screen.

The following is the best I could do. On startup the splash screen is
shown, then each form flickers briefly and then the main form is shown. If
I eliminate the .show/.hide commands, the forms don't flicker, but still take
a while to load when doing the first .show


This is the main form new event:
Public Sub New()
' create and display the splash screen form and make the main form
it's owner

splashScreen = New frmSplashScreen
splashScreen.Owner = Me
splashScreen.Show()

' process the message queue - this is done to allow the splash
screen to be painted
Application.DoEvents()

' disable the main form to avoid the title bar being drawn over the
splash screen during initialization
Me.Enabled = False


' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.

End Sub


Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'load all screens in background so they are all in ram when program
is loaded
fPowerScreen = New frmPower()
fLoadCurveScreen = New frmLoadCurve()
fCqmScreen = New frmCQM()
fToolsScreen = New frmTools()
fAutoSeqScreen = New frmAutoSequence()
fNumPad = New frmNumpadDialog()
fSignature = New frmSignature()

fPowerScreen.Show()
fPowerScreen.Hide()

fLoadCurveScreen.Show()
fLoadCurveScreen.Hide()

fCqmScreen.Show()
fCqmScreen.Hide()

fToolsScreen.Show()
fToolsScreen.Hide()

fAutoSeqScreen.Show()
fAutoSeqScreen.Hide()

fNumPad.Show()
fNumPad.Hide()


Me.Enabled = True
Me.Visible = True

' close the splash screen
splashScreen.Close()

End Sub
 
C

Chris Tacke, eMVP

Not really. All Forms and Controls need to be created on teh primary UI
thread. What you can do is:

1. Don't create the Forms until you need them.
2. Don't create extra "stuff" when you create the Form (i.e. keep static
initialization and ctor as short as possible)
3. Maybe use a Forms.Timer to initialize each form during startup.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
L

lsimoni

Even if I use a timer, wouldn't the screen flicker as I use the show/hide
routines? Is there any way to lock out the display refresh routine?

Thanks again for your help.
 
C

Chris Tacke, eMVP

Why are you using Show/Hide? Of course that would flicker. The fix is
simple - don't show it until you need to.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
L

lsimoni

That definitely works, I'm just trying to improve load performance. The
first time the form is loaded there is a several second delay. The first
time you show the form it takes about 4-5 seconds to show up. Then when the
form is hidden and then re-shown it takes less than a second.

The application has a main screen with several buttons on it. Each button
takes you to a different screen (form) with different functions. When you
want to change functions, you go back to the main screen and then to whatver
function you want to do. As a user, it looks strange if it takes 5 seconds
the first time a form is loaded vs. 1 second every other time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top