473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Threaded SplashScreen

I have a form that take a bit to load up because of talking to a database
and the amount of data process that has to take place before showing the
screen. I have it working but I feel that I horked it into working. I was
wondering if there was a better way to do this. Here are the two
interesting pieces of code. Thanks in Advance.
Sub Main
Dim Splash As New SplashScreen
Dim t As System.Threading.Thread
t = New System.Threading.Thread(AddressOf Splash.Process)
Splash.Show()
t.Start()
Dim CF As CommissionForm = New CommissionForm()
Splash.TimeToDie = True
t.Abort()
CF.ShowDialog()
End Sub

'This is Splash Screen code
Public Sub Process()
Do While Not Die
Application.DoEvents()
System.Threading.Thread.CurrentThread.Sleep(125)
Loop
Me.Hide()
Me.Close()
End Sub
Nov 21 '05 #1
9 2972
Nak
Hi Chris,

When I use threads I allways put the routine in a try block so that it
can be aborted easily,

~~~~~~~

Public Sub Main
Dim Splash As New SplashScreen
Call Splash.Show()

Dim t As New Threading.Thread(AddressOf Splash.Process)
t.Priority = ThreadPriority.BelowNormal
t.IsBackground = True
Call t.Start()

Dim CF As New CommissionForm()
Call CF.ShowDialog()

Call t.Abort()
End Sub

~~~~~~~

Public Sub Process
Try

'This will loop continually while no exceptions are encountered and
the form is created
While Me.Created()

'This will redraw the form if need be
Call Me.Refresh()

'This will cause the thread to yield to the operator
Call Threading.Thread.Sleep()
End While
Catch
End Try

'Close the form now!
Call Me.Close()
End Sub

~~~~~~~

Usually if I track progress I make a form that is displayed topmost and
I refresh it every time my intensive loop completes, but I guess in your
case the accessing of the database wont allow you to do this? If that is
the case and there is no other way to get asynchronous reading from a
database you may want to try to put the code that reads from the database
into a separate thread to prevent it from locking your application up, make
your own BeginRead and AbortRead methods. Then once you have that
implemented you can track the progress in the usual way.

I hope this helps!

Nick.
Nov 21 '05 #2
Nak
Hi Chris,

When I use threads I allways put the routine in a try block so that it
can be aborted easily,

~~~~~~~

Public Sub Main
Dim Splash As New SplashScreen
Call Splash.Show()

Dim t As New Threading.Thread(AddressOf Splash.Process)
t.Priority = ThreadPriority.BelowNormal
t.IsBackground = True
Call t.Start()

Dim CF As New CommissionForm()
Call CF.ShowDialog()

Call t.Abort()
End Sub

~~~~~~~

Public Sub Process
Try

'This will loop continually while no exceptions are encountered and
the form is created
While Me.Created()

'This will redraw the form if need be
Call Me.Refresh()

'This will cause the thread to yield to the operator
Call Threading.Thread.Sleep()
End While
Catch
End Try

'Close the form now!
Call Me.Close()
End Sub

~~~~~~~

Usually if I track progress I make a form that is displayed topmost and
I refresh it every time my intensive loop completes, but I guess in your
case the accessing of the database wont allow you to do this? If that is
the case and there is no other way to get asynchronous reading from a
database you may want to try to put the code that reads from the database
into a separate thread to prevent it from locking your application up, make
your own BeginRead and AbortRead methods. Then once you have that
implemented you can track the progress in the usual way.

I hope this helps!

Nick.
Nov 21 '05 #3
On Fri, 12 Nov 2004 13:11:58 -0600, Chris wrote:
Why not just show the splash screen and then close it when done? Why do
you need a thread?

Public Sub Main()
Dim Splash As New SplashScreen
Splash.Show()

Dim CF As CommissionForm = New CommissionForm()

Splash.Close
Application.Run(CF)
End Sub
--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #4
On Fri, 12 Nov 2004 13:11:58 -0600, Chris wrote:
Why not just show the splash screen and then close it when done? Why do
you need a thread?

Public Sub Main()
Dim Splash As New SplashScreen
Splash.Show()

Dim CF As CommissionForm = New CommissionForm()

Splash.Close
Application.Run(CF)
End Sub
--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #5
Nak
Hi Chris,

I think that if the applications thread gets blocked then the form will
not get refreshed, looking a bit on the pants side. Hence needing someway
of constantly keeping it repainted. At least that's what I presume he
means.

Nick.
Nov 21 '05 #6
Nak
Hi Chris,

I think that if the applications thread gets blocked then the form will
not get refreshed, looking a bit on the pants side. Hence needing someway
of constantly keeping it repainted. At least that's what I presume he
means.

Nick.
Nov 21 '05 #7
Chris,

Firstly, try to avoid using DoEvents. There are many situations where this
could prove deadly to your applications.

I would suggest showing the splash screen. Use ThreadStart to start your
job with a waithandle or a class that derrives the waithandle. This way,
you do not need a "nasty" loop containing DoEvents.

Hope this helps.

Landers

"Chris" <chris@No_Spam_Please.com> wrote in message
news:uW**************@TK2MSFTNGP12.phx.gbl...
I have a form that take a bit to load up because of talking to a database
and the amount of data process that has to take place before showing the
screen. I have it working but I feel that I horked it into working. I was wondering if there was a better way to do this. Here are the two
interesting pieces of code. Thanks in Advance.
Sub Main
Dim Splash As New SplashScreen
Dim t As System.Threading.Thread
t = New System.Threading.Thread(AddressOf Splash.Process)
Splash.Show()
t.Start()
Dim CF As CommissionForm = New CommissionForm()
Splash.TimeToDie = True
t.Abort()
CF.ShowDialog()
End Sub

'This is Splash Screen code
Public Sub Process()
Do While Not Die
Application.DoEvents()
System.Threading.Thread.CurrentThread.Sleep(125)
Loop
Me.Hide()
Me.Close()
End Sub

Nov 21 '05 #8
Landley-

Your post has brought up a couple of questions in my mind.

First, I use the DoEvents in several places in my application to make sure
the screen is in a clean state, is this a bad practice in general. For
instance I have a point where I got grab a bunch of data after a combobox is
changed. The combobox freezes and doesn't redraw until the blocking call is
done, so I run a doevents and it works perfect.

Not shown in that code I gave is a call to another sub that shows a progress
bar so the user sees something happening while loading. There are many DB
calls to get the data needed to show the user and there is a decent delay in
processing it all. I think I need the DoEvents for this progress bar to
update nicely, do you disagree with using it in this instance still?

Chris

"Landley" <ne**@creations-software.co.uk> wrote in message
news:eZ**************@TK2MSFTNGP14.phx.gbl...
Chris,

Firstly, try to avoid using DoEvents. There are many situations where
this
could prove deadly to your applications.

I would suggest showing the splash screen. Use ThreadStart to start your
job with a waithandle or a class that derrives the waithandle. This way,
you do not need a "nasty" loop containing DoEvents.

Hope this helps.

Landers

"Chris" <chris@No_Spam_Please.com> wrote in message
news:uW**************@TK2MSFTNGP12.phx.gbl...
I have a form that take a bit to load up because of talking to a database
and the amount of data process that has to take place before showing the
screen. I have it working but I feel that I horked it into working. I

was
wondering if there was a better way to do this. Here are the two
interesting pieces of code. Thanks in Advance.
Sub Main
Dim Splash As New SplashScreen
Dim t As System.Threading.Thread
t = New System.Threading.Thread(AddressOf Splash.Process)
Splash.Show()
t.Start()
Dim CF As CommissionForm = New CommissionForm()
Splash.TimeToDie = True
t.Abort()
CF.ShowDialog()
End Sub

'This is Splash Screen code
Public Sub Process()
Do While Not Die
Application.DoEvents()
System.Threading.Thread.CurrentThread.Sleep(125)
Loop
Me.Hide()
Me.Close()
End Sub


Nov 21 '05 #9
Nak
Sorry to jump in. But you might want to check this out,

http://geekswithblogs.net/jolson/articles/2173.aspx

This guy explains why you shouldn't use DoEvents in a game loop, and it's
pretty much for the same reason (in my opinion), especially if you are just
using it to enable the redrawing of a thread blocked form. *But*, that
doesn't mean you shouldn't use DoEvents full stop, you can "selectively"
yield to the operator by checking the message cue for any pending messages
*before* calling DoEvents, use the following to achieve this,

Private Const QS_HOTKEY As Integer = &H80
Private Const QS_KEY As Integer = &H1
Private Const QS_MOUSEBUTTON As Integer = &H4
Private Const QS_MOUSEMOVE As Integer = &H2
Private Const QS_PAINT As Integer = &H20
Private Const QS_POSTMESSAGE As Integer = &H8
Private Const QS_SENDMESSAGE As Integer = &H40
Private Const QS_TIMER As Integer = &H10
Private Const QS_ALLPOSTMESSAGE As Integer = &H100
Private Const QS_MOUSE As Integer = (QS_MOUSEMOVE Or QS_MOUSEBUTTON)
Private Const QS_INPUT As Integer = (QS_MOUSE Or QS_KEY)
Private Const QS_ALLEVENTS As Integer = (QS_INPUT Or QS_POSTMESSAGE Or
QS_TIMER Or QS_PAINT Or QS_HOTKEY)
Private Const QS_ALLINPUT As Integer = (QS_SENDMESSAGE Or QS_PAINT Or
QS_TIMER Or QS_POSTMESSAGE Or QS_MOUSEBUTTON Or QS_MOUSEMOVE Or QS_HOTKEY Or
QS_KEY)
Private Declare Function GetQueueStatus Lib "user32" (ByVal fuFlags As
Integer) As Integer

Public Sub selectiveYield()
If (CBool(GetQueueStatus(QS_ALLINPUT))) Then Call Application.DoEvents()
End Sub

I'm sure that Landers solution sounds more robust, but this can be
quickly implemented at key points during the application to prevent your
loop from slowing down unneccesarily by yielding with each loop. Hope this
helps.

Nick.
"Chris" <chris@No_Spam_Please.com> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
Landley-

Your post has brought up a couple of questions in my mind.

First, I use the DoEvents in several places in my application to make sure
the screen is in a clean state, is this a bad practice in general. For
instance I have a point where I got grab a bunch of data after a combobox
is changed. The combobox freezes and doesn't redraw until the blocking
call is done, so I run a doevents and it works perfect.

Not shown in that code I gave is a call to another sub that shows a
progress bar so the user sees something happening while loading. There
are many DB calls to get the data needed to show the user and there is a
decent delay in processing it all. I think I need the DoEvents for this
progress bar to update nicely, do you disagree with using it in this
instance still?

Chris

"Landley" <ne**@creations-software.co.uk> wrote in message
news:eZ**************@TK2MSFTNGP14.phx.gbl...
Chris,

Firstly, try to avoid using DoEvents. There are many situations where
this
could prove deadly to your applications.

I would suggest showing the splash screen. Use ThreadStart to start your
job with a waithandle or a class that derrives the waithandle. This way,
you do not need a "nasty" loop containing DoEvents.

Hope this helps.

Landers

"Chris" <chris@No_Spam_Please.com> wrote in message
news:uW**************@TK2MSFTNGP12.phx.gbl...
I have a form that take a bit to load up because of talking to a
database
and the amount of data process that has to take place before showing the
screen. I have it working but I feel that I horked it into working. I

was
wondering if there was a better way to do this. Here are the two
interesting pieces of code. Thanks in Advance.
Sub Main
Dim Splash As New SplashScreen
Dim t As System.Threading.Thread
t = New System.Threading.Thread(AddressOf Splash.Process)
Splash.Show()
t.Start()
Dim CF As CommissionForm = New CommissionForm()
Splash.TimeToDie = True
t.Abort()
CF.ShowDialog()
End Sub

'This is Splash Screen code
Public Sub Process()
Do While Not Die
Application.DoEvents()
System.Threading.Thread.CurrentThread.Sleep(125)
Loop
Me.Hide()
Me.Close()
End Sub



Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Yavuz Bogazci | last post by:
Hi, where can i download a sample SplashScreen Project? I need one with showing Information like License, Regged User, initialize Database ... (like the Adobe Splashscreens) ... and then show...
10
by: Bob | last post by:
I have a splashscreen running on a thread from Sub Main and it works OK. It displays information in a statusbar about queries. I also have a time on the splashscreen, but the tick event never...
0
by: Chris | last post by:
I have a form that take a bit to load up because of talking to a database and the amount of data process that has to take place before showing the screen. I have it working but I feel that I...
6
by: ben | last post by:
I am needing a web service to be single threaded. Is this possible? Any ideas would be helpful
1
by: Maurice Mertens | last post by:
Hi, I'm currently working on an app in VB.NET 2005 which uses a splashscreen. In the 'my project' settings I used the 'Spash screen' setting to set the form that will be the splash screen. ...
4
by: steve | last post by:
Hi All I have a form set as the splashscreen in project properties Is there any way to get msgboxes to appear on top of the splashscreen If I don't hide the splashscreen then the program...
14
by: Snor | last post by:
I'm attempting to create a lobby & game server for a multiplayer game, and have hit a problem early on with the server design. I am stuck between using a threaded server, and using an event driven...
7
myusernotyours
by: myusernotyours | last post by:
Am trying to create a splash screen using the SplashScreen class. i edit the manifest file to be put in to the jar file and also put the .gif file in the application directory but the method returns...
14
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
As far as I know, the C Standard has no mention of multi-threaded programming; it has no mention of how to achieve multi-threaded programming, nor does it mention whether the language or its...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.