How to suspend a thread which is in WaitSleepJoin state.


Sakharam Phapale

Hi All,

In following example, while playing file, if thread goes in WaitSleepJoin
state, due to Thread.Sleep method.
Now I want to suspend thread by clicking on cmdSuspend button. I have
written following code, which doesn't suspend it.
Even I tried it by calling m_PlayThread.Interrupt() method which suspends
the thread but cannot resume it again by calling Resume method.

Any kind help will be appreciated.

Thanks and Regards
Sakharam Phapale


Private m_IsStop As Boolean

Private sub PlayAudio()
m_IsStop = False
For intLoopCounter = 0 To m_intNoOfFiles
m_PlayThread.Sleep(lngPlayToTime - lngPlayFromTime)
If m_IsStop Then
End If
Catch Ex As Exception
End Try
End Sub

Private Sub cmdPlay_Click(Sender As Object, ------)
Dim m_PlayThread as New Threading.Thread(AddressOf PlayAudio)
End Sub

Private Sub cmdPause_Click(sender as Object,-------)
End Sub

Private Sub cmdResume_Click(--------)
End Sub

Private Sub cmdStop_Click(--------)
m_IsStop = True
If m_PlayThread.ThreadState = WaitSleepJoin Then
End If
End Sub

Jay B. Harlow [MVP - Outlook]

What are you expecting Thead.Suspend to suspend?

The playing of the music? It cannot do this, as you using the
objAudioRecorderPlayer object to control playing of the music, you don't
tell us what the objAudioRecorderPlayer is, but I suspect it has its own
thread to play the music (you are using a thread to control a thread, to
control yet another thread, and you are one thread away from where you need
to be...)

Thread.Interrupt actually wakes up a thread, by causing a
ThreadInterruptedException to be raised on that thread.

I would expect the objAudioRecorderPlayer to have methods to suspend,
resume, and stop playback of the music. The trick is going to be is you need
to suspend both your thread & objAudioRecorderPlayer, resume both
objAudioRecorderPlayer & your thread, plus stop your thread &

As the thread the Cor suggested, I would review other playback methods other
then objAudioRecorderPlayer. Or preferable I would research
objAudioRecorderPlayer to learn how to have it playback sounds without an
unneeded thread in my app, as I strongly suspect it already is doing all the
threading it needs via some ASYNC option.

As I stated in the other thread:

I would think (hope) what ever you are using to play sounds has a similar
asynchronous setting.

If I needed to use a thread in my app, then I would use the PlaySounds API
directly without having the objAudioRecorderPlayer object in the way...

Hope this helps

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