473,805 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to suspend a thread which is in WaitSleepJoin state.

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.In terrupt() 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_objAudioRecor derPlayer.OpenF ile(m_arrFiles( intLoopCounter) )
m_objAudioRecor derPlayer.Start Playing(m_lngPl ayFromTime,
m_lngPlayToTime )
m_PlayThread.Sl eep(lngPlayToTi me - lngPlayFromTime )
If m_IsStop Then
m_objAudioRecor derPlayer.Close File()
End If
Catch Ex As Exception
m_objAudioRecor derPlayer.Close File()
End Try
Loop
End Sub

Private Sub cmdPlay_Click(S ender As Object, ------)
Dim m_PlayThread as New Threading.Threa d(AddressOf PlayAudio)
m_PlayThread.St art()
End Sub

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

Private Sub cmdResume_Click (--------)
m_PlayThread.Re sume()
End Sub

Private Sub cmdStop_Click(--------)
m_IsStop = True
If m_PlayThread.Th readState = WaitSleepJoin Then
m_PlayThread.In terrupt()
End If
End Sub

----------------------------------------------------------------------------
-------------
Nov 21 '05 #1
2 2303
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
Sakharam,
What are you expecting Thead.Suspend to suspend?

The playing of the music? It cannot do this, as you using the
objAudioRecorde rPlayer object to control playing of the music, you don't
tell us what the objAudioRecorde rPlayer 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.Interrup t actually wakes up a thread, by causing a
ThreadInterrupt edException to be raised on that thread.

I would expect the objAudioRecorde rPlayer 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 & objAudioRecorde rPlayer, resume both
objAudioRecorde rPlayer & your thread, plus stop your thread &
objAudioRecorde rPlayer...

As the thread the Cor suggested, I would review other playback methods other
then objAudioRecorde rPlayer. Or preferable I would research
objAudioRecorde rPlayer 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 objAudioRecorde rPlayer object in the way...

Hope this helps
Jay

"Sakharam Phapale" <sp******@annet site.com> wrote in message
news:OY******** ******@tk2msftn gp13.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.In terrupt() 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_objAudioRecor derPlayer.OpenF ile(m_arrFiles( intLoopCounter) )
m_objAudioRecor derPlayer.Start Playing(m_lngPl ayFromTime,
m_lngPlayToTime )
m_PlayThread.Sl eep(lngPlayToTi me - lngPlayFromTime )
If m_IsStop Then
m_objAudioRecor derPlayer.Close File()
End If
Catch Ex As Exception
m_objAudioRecor derPlayer.Close File()
End Try
Loop
End Sub

Private Sub cmdPlay_Click(S ender As Object, ------)
Dim m_PlayThread as New Threading.Threa d(AddressOf PlayAudio)
m_PlayThread.St art()
End Sub

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

Private Sub cmdResume_Click (--------)
m_PlayThread.Re sume()
End Sub

Private Sub cmdStop_Click(--------)
m_IsStop = True
If m_PlayThread.Th readState = WaitSleepJoin Then
m_PlayThread.In terrupt()
End If
End Sub

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

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2781
by: Keith Langer | last post by:
I have an application which consists of a main work thread and multiple threads which each maintain a TCP socket. When a configuration change occurs, all activity on the socket threads must be halted. If a socket is no longer in the configuration, that thread must be aborted and the socket must be closed. After the configuration is complete, the remaining threads must be resumed. I currently have the following architecture:
16
2053
by: Alvin Bruney | last post by:
I'm observing that a sleeping thread changes to stopped after a while. Is that accepted framework behavior for web applications? My thread basically does some work, and sleeps for 60 minutes before calling itself recursively, which means it is supposed to run on the hour every hour. But it automatically stops after 2 hours. I only get 2 emails, 1 per hour and then nothing. When I examine the threadstate during run-time, it has changed...
8
36469
by: Wim | last post by:
My GUI application starts a process (a console program) when the user hits Play. I would like to add an option to pause that process. The code I've added to detect if the user hit pause/unpause seems to work. But I have no clue how to pause/suspend the process. As far as I can see the Process class doesn't offer anything for this. So it's probably the thread the process is running on that should be suspended or put to sleep. But just...
1
6455
by: Sakharam Phapale | last post by:
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.
1
1657
by: Paul Tomlinson | last post by:
Quick question. If i call Thread.suspend() on a thread does the thread which is being suspended get any notification that it has been/is being suspended? I am thinking i want the thread-to-be-suspended to log the fact that it is being suspended. Any ideas?
4
11112
by: am | last post by:
Hi to all. I have a little problem. I'm working with threads, and I need to abort or suspend them, but many experts dissuade from use Thread.Abort and Thread.Suspend. As I didn't find other way, how can I do? Thanks a lot!
2
1637
by: b.fokke | last post by:
Hi all! I'm working on an application that due to the nature of the application is heavily concurrent. Usually, there will be between 15 and 20 threads running at the same time. However, at some times it might be necessary to pause execution of these threads. Thread.Suspend() looks like an excellent candidate, but the method is deprecated in the framework. According to the documentation I should use dedicated objects like Monitors for...
6
1418
by: Robert Speck | last post by:
Hi there, Can anyone shed anymore light on why "Thread.Suspend()" has been deprecated by MSFT beyond what MSDN says about it. I'm not sure if I quite appreciate the various pitfalls they discuss but using it under certain circumstances still seems reasonable. For instance, I want to display a small modal dialog with a "Cancel" button which allows the user to abort a background thread. If the user clicks this button, I then want to prompt...
3
6062
by: =?Utf-8?B?TWFyayBDaGFubmluZw==?= | last post by:
I have a code which registers all threads with a thread dump class. At intervals this thread dump class will dump the stack trace of all threads. As calling StackTrace(threadtoDump) from a different thread other than the treadToDump the threadToDump must be suspended otherwise a ThreadStateException gets thrown. However under .NET 2.0 System.Threading.Thread.Suspend/Resume have been marked as obsolete with reference to better methods of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10359
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
10364
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
9182
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
7645
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
6875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.