CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2011

    How to use Sleep() correctly

    I'm trying to use the Thread.Sleep() function, but when I do it is not working correctly.

    I want to do some actions, sleep for 2 seconds, then do some more actions. However, the actions that should occur before the sleep are happening after. I'm not sure how to do this better. Here's my code:

    ((ImageView) v).setImageDrawable(drawables[i][j]);
    //Play the sound
    MediaPlayer mp = MediaPlayer.create(getBaseContext(), R.raw.trucksound);

    Thread.currentThread().sleep(delay);//sleep for 1000 ms
    catch(InterruptedException ie){

    Thanks for your help.

  2. #2
    Join Date
    Jun 1999
    Eastern Florida

    Re: How to use Sleep() correctly

    What are the actions that are being held up?
    If you are sleeping on the same thread that the is used to do the action, then you are preventing the action from happening until you release the thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.