newbie thread mishap



Short version:

myThread.Suspend() is suspending my entire application and I don't
understand why.

Long version:

I have a form that I want to pop up frequently throughout my application,
it's essentially a 'please wait' message in a fancy-graphic form. The
program can perform a number of semi-lengthy processes, so I'd like to make
it easy for me to throw up a splash on a whim. It's the only thread I'm
creating in my app.

I thought it would be an interesting learning exercise & experiment to place
this please wait splash screen into a sepereate thread, which I could
suspend & hide / resume & show at will throughout the program. And I
thought the fact that the splash is a little animated might be helped by
running it in a seperate thread. Never the less, I set up a small class
that suspends the thread & hides the form /resumes the thread & shows the

The method that "shows/resumes" is smart enough to know whether or not the
thread needs to be run anew, or simply resumed by checking it's isAlive

When I run the main program eventually the code comes to the first point
where it wants to show a splash screen. It calls the "show/resume" method,
which correctly figures out it needs to run the thread (as opposed to resume
the thread), the form shows up and animates while the main apps processes
work away. The main app finishes what it's doing and calls the
"hide/suspend" method. This appears to suspend both the splash screen and
the main app. I'm just using myThread.Suspend(). Why would that suspend my
entire app?

CJ Taylor

Show some of your code from your class. It sounds like your jsut suspending
the wrong thread.



Here's the test I'm trying to work with; modMain casts an instance of my
threaded splash class & calls the showSplash() method. It performs a
security check that may take 0.5 to 5.0 seconds or more in the main thread
while the splash runs in the other thread.



Public frmMain As New clsfrmMain
Public frmSplash As New clsfrmSplash
Public clsThdSplash As New clsThreadedSplash(frmSplash)

Sub Main()


If Not theLongSecurityCheck() Then
msgbox("Access denied")
End If


End Sub

[End modMain.vb]


Public Class clsThreadedSplash

Private frmThreadsForm As Form
Private ctrlThreadsControl As clsctrlSplashScreen
Private frmForm As Form
Private thdThread As New Threading.Thread(AddressOf

Public Sub New(ByRef SplashForm As Form)

frmForm = SplashForm
thdThread.IsBackground = True
thdThread.Name = "splashScreenThread"
thdThread.Priority = Threading.ThreadPriority.Normal

End Sub

Public Sub hideSplash()


End Sub

Public Sub showSplash()

If thdThread.IsAlive Then
Select Case thdThread.ThreadState - 4
Case Is = Threading.ThreadState.Suspended
End Select
End If

End Sub

Public Sub threadedSplashScreen()


End Sub

End Class

[End clsThreadedSplash.vb]


Note this all occurs prior to the "main" Application.Run() call in Sub Main,
is that part of my problem? If this code is run, I get the splash... it
animates, it becomes hidden and next I see frmMain; but it's suspended, I
can't work with it, mouse is just an hourglass & no controls appear on it.
Also, if I remove the frmForm.Hide() line from the hideSplash() method, same
results except it ends with both forms on the screen, unresponsive as
described previously. It's almost as if the Application.Run(frmForm) call
in the threadedSplashScreen() member is assuming the role of the main
application thread...? Dunno. If I remove the suspend call all together,
both forms run happily on the screen. So I *could* cheat, and just hide the
splash form and do away with suspending the thread all together, but that
would certainly defeat my intentions of learning about what's going on here.

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