Basic threading question...

B2Ben

Well-known member
Joined
Aug 17, 2006
Messages
52
Programming Experience
Beginner
I'm digging into some threading for the first time, but Im running into an issue in VS.NET 2005...

VB.NET:
Private PicFadeThread As New System.Threading.Thread(AddressOf DoFade)

Public Sub StartFade()
        '...do some stuff...
        PicFadeThread.Start()
End Sub

Private Sub DoFade()
        '...do stuff in my thread...
        '(This is not an endless loop... this code ends at some point)
End Sub
I can call StartFade() once, and my DoFade code runs in a separate thread, as it should. Once the DoFade() sub finishes, I would assume the separate thread dies... but it doesn't seem to be happening that way. If I try running StartFade() again, it crashes. I want to start the DoFade() code again. How can I accomplish this?

Thanks!
 
OK... I think I got it... I built a separate test app to help me figure out what was happening. AFter the thread ran, it was "stopped" and trying to "start" it again caused an exception. So I moved my thread constructor into the StartFade() sub, thus re-creating it each time I execute StartFade()

My only concern is that I don't know if this will build up many threads in memory over tiem and cause problems... or if the thread is "replaced" each time. If anybody can shed some on light on my concern, it would be appreciated.

VB.NET:
Private PicFadeThread As System.Threading.Thread
 
Public Sub StartFade()
        Me.PicFadeThread = New System.Threading.Thread(AddressOf DoFade)
        '...do some stuff...
        PicFadeThread.Start()
End Sub
 
Private Sub DoFade()
        '...do stuff in my thread...
        '(This is not an endless loop... this code ends at some point)
End Sub
 
You need to have a look into ThreadPool

That should sort out your worries.
 
Solution for Basic Threading Questions

Once you start the thread, Time interval has to be set using sleep method then you have to check the thread status using threadstate method. If already thread is running use suspend method.

venkat
 
Back
Top