How do I pause a thread indefinitely?

Reply

Join Date: Feb 2008
Posts: 36
Reputation: esy928 is an unknown quantity at this point 
Solved Threads: 0
esy928 esy928 is offline Offline
Light Poster

How do I pause a thread indefinitely?

 
0
  #1
Aug 25th, 2008
How do I pause a thread indefinitely? im creating a game and i need a thread to be paused when the user pauses the game and the thread will resume when the user unpauses the game. =) im using thread.sleep right now but it requires an integer to determine how long it will pause, but since i dont know how long the user is gonna pause the game, i think that method wont do me any good.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: How do I pause a thread indefinitely?

 
0
  #2
Aug 25th, 2008
this might be an option
  1. public static void pauze(){
  2. while(!isContinue()){
  3. //keep the duration small, so the game will be resumed shortly after
  4. // the user presses resume
  5. sleep(500);
  6. }
  7. }
  8.  
  9. public static boolean isContinue(){
  10. boolean returnVal = false;
  11. // this method checks in the rest of your code, whether or not your user pressed resume
  12. //returnVal = ....
  13.  
  14. return returnVal;
  15. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 36
Reputation: esy928 is an unknown quantity at this point 
Solved Threads: 0
esy928 esy928 is offline Offline
Light Poster

Re: How do I pause a thread indefinitely?

 
0
  #3
Aug 25th, 2008
thanks =) ill give it a try
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: How do I pause a thread indefinitely?

 
0
  #4
Aug 25th, 2008
Originally Posted by stultuske View Post
this might be an option
  1. public static void pauze(){
  2. while(!isContinue()){
  3. //keep the duration small, so the game will be resumed shortly after
  4. // the user presses resume
  5. sleep(500);
  6. }
  7. }
  8.  
  9. public static boolean isContinue(){
  10. boolean returnVal = false;
  11. // this method checks in the rest of your code, whether or not your user pressed resume
  12. //returnVal = ....
  13.  
  14. return returnVal;
  15. }
That's a very expensive method call. Your primary thread operation will have to wait for the calculation of isContinue() if you were to do it that way.

You may instead want to have a set method that sets the boolean expression in the loop to false so that the process can stop when it is desired for it to stop.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC