473,785 Members | 2,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Threadin g.Thread
t = New System.Threadin g.Thread(Addres sOf Splash.Process)
Splash.Show()
t.Start()
Dim CF As CommissionForm = New CommissionForm( )
Splash.TimeToDi e = True
t.Abort()
CF.ShowDialog()
End Sub

'This is Splash Screen code
Public Sub Process()
Do While Not Die
Application.DoE vents()
System.Threadin g.Thread.Curren tThread.Sleep(1 25)
Loop
Me.Hide()
Me.Close()
End Sub
Nov 21 '05 #1
9 2993
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.Threa d(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.Threa d.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.Threa d(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.Threa d.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_lunch meat_[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_lunch meat_[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******** ******@TK2MSFTN GP12.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.Threadin g.Thread
t = New System.Threadin g.Thread(Addres sOf Splash.Process)
Splash.Show()
t.Start()
Dim CF As CommissionForm = New CommissionForm( )
Splash.TimeToDi e = True
t.Abort()
CF.ShowDialog()
End Sub

'This is Splash Screen code
Public Sub Process()
Do While Not Die
Application.DoE vents()
System.Threadin g.Thread.Curren tThread.Sleep(1 25)
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**@creatio ns-software.co.uk> wrote in message
news:eZ******** ******@TK2MSFTN GP14.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******** ******@TK2MSFTN GP12.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.Threadin g.Thread
t = New System.Threadin g.Thread(Addres sOf Splash.Process)
Splash.Show()
t.Start()
Dim CF As CommissionForm = New CommissionForm( )
Splash.TimeToDi e = True
t.Abort()
CF.ShowDialog()
End Sub

'This is Splash Screen code
Public Sub Process()
Do While Not Die
Application.DoE vents()
System.Threadin g.Thread.Curren tThread.Sleep(1 25)
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 "selectivel y"
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_ALLPOSTMESSA GE 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(GetQueue Status(QS_ALLIN PUT))) Then Call Application.DoE vents()
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******** ******@TK2MSFTN GP09.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**@creatio ns-software.co.uk> wrote in message
news:eZ******** ******@TK2MSFTN GP14.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******** ******@TK2MSFTN GP12.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.Threadin g.Thread
t = New System.Threadin g.Thread(Addres sOf Splash.Process)
Splash.Show()
t.Start()
Dim CF As CommissionForm = New CommissionForm( )
Splash.TimeToDi e = True
t.Abort()
CF.ShowDialog()
End Sub

'This is Splash Screen code
Public Sub Process()
Do While Not Die
Application.DoE vents()
System.Threadin g.Thread.Curren tThread.Sleep(1 25)
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
1583
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 the Main Form. thanks yavuz bogazci
10
1840
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 gets fired. In the Load Event if the splashscreen I call the timer's Start() event. HOw do I get the tick event to fire?
0
284
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 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
6
4964
by: ben | last post by:
I am needing a web service to be single threaded. Is this possible? Any ideas would be helpful
1
1760
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. The next thing I want to do is change the text of a control on this form so the app can show some information about the startup proces. There's a control ctlText on the Splashscreen. I also have this property on
4
5111
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 just stops as msgbxes from licence checks etc cannot load on top
14
2121
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 server. I've been told time and time again that I should use an event driven server design (that is, use twisted). There is a lot of interaction between the clients and they would often need to write to the same list of values, which of course...
7
9596
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 null all the time. Should the .gif file be inside the jar and how do i get it there. Am using netbeans 6 and it automatically builds the jar.
14
3414
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 libraries are suitable for multi-threaded programming. For people who are fond of portable C programming, what's the best way to go about multi-threaded programming? I've been reading up on POSIX threads a little, they seem pretty ubiquitous....
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10090
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9949
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.