By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,037 Members | 1,839 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,037 IT Pros & Developers. It's quick & easy.

How to suspend a thread which is in WaitSleepJoin state.

P: n/a
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
Try
m_objAudioRecorderPlayer.OpenFile(m_arrFiles(intLo opCounter))
m_objAudioRecorderPlayer.StartPlaying(m_lngPlayFro mTime,
m_lngPlayToTime)
m_PlayThread.Sleep(lngPlayToTime - lngPlayFromTime)
If m_IsStop Then
m_objAudioRecorderPlayer.CloseFile()
End If
Catch Ex As Exception
m_objAudioRecorderPlayer.CloseFile()
End Try
Loop
End Sub

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

Private Sub cmdPause_Click(sender as Object,-------)
m_PlayThread.Suspend()
End Sub

Private Sub cmdResume_Click(--------)
m_PlayThread.Resume()
End Sub

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

----------------------------------------------------------------------------
-------------
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Sakharam,

I have seen this message before in my opinion.

http://groups-beta.google.com/group/...2f8eddc2ee4b08

With a lot of answers.

Cor
Nov 21 '05 #2

P: n/a
Sakharam,
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 &
objAudioRecorderPlayer...

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
Jay

"Sakharam Phapale" <sp******@annetsite.com> wrote in message
news:OY**************@tk2msftngp13.phx.gbl...
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
Try
m_objAudioRecorderPlayer.OpenFile(m_arrFiles(intLo opCounter))
m_objAudioRecorderPlayer.StartPlaying(m_lngPlayFro mTime,
m_lngPlayToTime)
m_PlayThread.Sleep(lngPlayToTime - lngPlayFromTime)
If m_IsStop Then
m_objAudioRecorderPlayer.CloseFile()
End If
Catch Ex As Exception
m_objAudioRecorderPlayer.CloseFile()
End Try
Loop
End Sub

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

Private Sub cmdPause_Click(sender as Object,-------)
m_PlayThread.Suspend()
End Sub

Private Sub cmdResume_Click(--------)
m_PlayThread.Resume()
End Sub

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

----------------------------------------------------------------------------
-------------

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.