Program Startup

J

John Wright

During my program startup I need to check for a couple of things.
1. I need to check for network availability
2. I need to check for database connectivity
3. I need to check for access to the server via a webservice

I have written the code to do all of these things. Now I want to put them
into a startup form. I want to load my main form, but from the main form I
want to call a splash screen with an animation on it that will cycle through
all the above events. This will let the user know there is action going on.
Also, if the network or database connection fails, I want to prevent them
from using the program or store the files locally. If the server cannot be
accessed, I will write the data to the database then process later. Again
the code for these actions are done. What I need is a really good way of
showing a splash screen, update a label on the splash screen while checking
for these items, then close the splash screen.

I can load the splash screen as follows

Dim mySplash as new splashScreen
mySplash.Show

This will show the screen, but I need suggestions to update the label on the
screen while checking for the items above. Anyone have a good idea or can
point me to an article on a good way to use a splash screen?

Thanks.

John
 
R

rowe_newsgroups

During my program startup I need to check for a couple of things.
    1.  I need to check for network availability
    2.  I need to check for database connectivity
    3.  I need to check for access to the server via a webservice

I have written the code to do all of these things.  Now I want to put them
into a startup form.  I want to load my main form, but from the main form I
want to call a splash screen with an animation on it that will cycle through
all the above events.  This will let the user know there is action going on.
Also, if the network or database connection fails, I want to prevent them
from using the program or store the files locally.  If the server cannot be
accessed, I will write the data to the database then process later.  Again
the code for these actions are done.  What I need is a really good way of
showing a splash screen, update a label on the splash screen while checking
for these items, then close the splash screen.

I can load the splash screen as follows

Dim mySplash as new splashScreen
mySplash.Show

This will show the screen, but I need suggestions to update the label on the
screen while checking for the items above.  Anyone have a good idea or can
point me to an article on a good way to use a splash screen?

Thanks.

John

If it were me, I'd start the application from a module using Sub
Main(), show the splash screen, and pop events from the module that
the splash screen would subscribe to. These events would contain the
text to display on the splash screen and any other applicable data.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
J

John Wright

Okay,

I set up a sub main to run and raised events. I subscribed to these events
in the form using event handlers. I simulated the connections and ran. I
got the outline of the form which appears while the process runs then it
goes away.

So I tried a background worker thread with the same results. Do I need to
refresh the form? How can I show the form all the way on a load like this?

John
 
R

rowe_newsgroups

Okay,

I set up a sub main to run and raised events.  I subscribed to these events
in the form using event handlers.  I simulated the connections and ran. I
got the outline of the form which appears while the process runs then it
goes away.

So I tried a background worker thread with the same results.  Do I needto
refresh the form?  How can I show the form all the way on a load like this?

The problem is most likely that your connectivity checks are occurring
too fast, you'll probably need to add in some logic to keep the splash
screen showing for a while. Before doing anything heavy duty, you
could try opening the form on a seperate thread and then doing a
Thread.Sleep(1000) between the connectivity checks in Sub Main. If
that works you can look at writing the long term solution.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
J

John Wright

Here is the code that is doing the checks on the form:

Threading.Thread.Sleep(4000)

CheckNetwork()

Threading.Thread.Sleep(4000)

CheckDB()

Threading.Thread.Sleep(4000)

CheckEPN()

Threading.Thread.Sleep(4000)

My.Forms.frmMain.Show()

I am doing a sleep for 4 seconds between calls. Also, when I load the form,
the animation loads just fine, but the first call to the method that updates
the label freezes the animation and the form until it is loaded. I'll just
keep plugging at it I guess.



John

Okay,

I set up a sub main to run and raised events. I subscribed to these events
in the form using event handlers. I simulated the connections and ran. I
got the outline of the form which appears while the process runs then it
goes away.

So I tried a background worker thread with the same results. Do I need to
refresh the form? How can I show the form all the way on a load like this?

The problem is most likely that your connectivity checks are occurring
too fast, you'll probably need to add in some logic to keep the splash
screen showing for a while. Before doing anything heavy duty, you
could try opening the form on a seperate thread and then doing a
Thread.Sleep(1000) between the connectivity checks in Sub Main. If
that works you can look at writing the long term solution.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
R

rowe_newsgroups

Here is the code that is doing the checks on the form:

Threading.Thread.Sleep(4000)

CheckNetwork()

Threading.Thread.Sleep(4000)

CheckDB()

Threading.Thread.Sleep(4000)

CheckEPN()

Threading.Thread.Sleep(4000)

My.Forms.frmMain.Show()

I am doing a sleep for 4 seconds between calls.  Also, when I load the form,
the animation loads just fine, but the first call to the method that updates
the label freezes the animation and the form until it is loaded.  I'll just
keep plugging at it I guess.

John






The problem is most likely that your connectivity checks are occurring
too fast, you'll probably need to add in some logic to keep the splash
screen showing for a while. Before doing anything heavy duty, you
could try opening the form on a seperate thread and then doing a
Thread.Sleep(1000) between the connectivity checks in Sub Main. If
that works you can look at writing the long term solution.

Thanks,

Seth Rowe [MVP]http://sethrowe.blogspot.com/

Is the splash screen being loading / shown on a thread separate from
the one the checks are being done on? In order for thread.sleep(...)
to not effect the splash screen, it needs to be on a separate thread.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
J

John Wright

Got it to work. Here is what I did.

On my splash screen I created the following:
Public Delegate Sub UpdateStatusDelegate(ByVal Status As String, ByVal
progress As Integer)

Then I created the following Sub on the splash screen to call:

Public Sub UpdateStatus(ByVal status As String, ByVal progress As Integer)

If Me.InvokeRequired Then

Me.Invoke(New UpdateStatusDelegate(AddressOf Me.UpdateStatus), New Object()
{status, progress})

Else

Me.lblStatus.Text = status

Me.ProgressBar1.Value = progress

End If

Me.Refresh()

End Sub

Then from the main form I call as follows (to simulate the load for now, I
will call the updatestatus as I load):

EPNSplash.Show()

EPNSplash.UpdateStatus("Starting EPN...", 20)

Threading.Thread.Sleep(3000)

EPNSplash.UpdateStatus("Checking Network...", 40)

Threading.Thread.Sleep(3000)

EPNSplash.UpdateStatus("Checking Database...", 60)

Threading.Thread.Sleep(3000)

EPNSplash.UpdateStatus("Connecting to EPN system...", 80)

Threading.Thread.Sleep(3000)

EPNSplash.UpdateStatus("Program loaded.Initializing...", 100)

Threading.Thread.Sleep(3000)

EPNSplash.Close()

Works like a charm. Thanks one and all for the help.



John
 

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