Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8261765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:31:37+00:00 2026-06-08T03:31:37+00:00

I want to cause my program to pause for a certain number of milliseconds,

  • 0

I want to cause my program to pause for a certain number of milliseconds, how exactly would I do this?

I have found different ways such as Thread.sleep( time ), but I don’t think that is what I need. I just want to have my code pause at a certain line for x milliseconds. Any ideas would be greatly appreciated.

This is the original code in C…

extern void delay(UInt32 wait){
    UInt32 ticks;
    UInt32  pause;

    ticks = TimGetTicks();
    //use = ticks + (wait/4);
    pause = ticks + (wait);
    while(ticks < pause)
        ticks = TimGetTicks();
}

wait is an amount of milliseconds

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:31:38+00:00Added an answer on June 8, 2026 at 3:31 am

    OK, first of all, never implement a delay with a busy loop as you’re doing. I can see where that comes from — I’m guessing that the palm pilot was a single-process device with no built-in sleep() function, but on a multi-process device, a busy loop like that just brings the entire processor to its knees. It kills your battery, prevents normal system tasks from running properly, slows down other programs or stops them completely, makes the device unresponsive, and can even cause it to get hot in your hands.

    The call you’re looking for is Thread.sleep(). You’ll need to set up to catch any interrupt exceptions that occur while you’re sleeping.

    Second, with event-based user interfaces such as Android (or pretty much any modern GUI system), you never want to sleep in the UI thread. That will also freeze up the entire device and result in an ANR (Activity Not Responding) crash, as other posters have mentioned. Most importantly, those little freezes totally ruin the user experience.

    (Exception: if you’re sleeping for short enough intervals that the user probably won’t notice, you can get away with it. 1/4 second is probably ok, although it can make the application janky depending on the situation.)

    Unfortunately, there’s no clean and elegant way to do what you want if what you’re doing is porting a loop-based application to an event-based system.

    That said, the proper procedure is to create a handler in your UI thread and send delayed messages to it. The delayed messages will “wake up” your application and trigger it to perform whatever it was going to do after the delay.

    Something like this:

    View gameBoard;     // the view containing the main part of the game
    int gameState = 0;  // starting
    Handler myHandler;
    
    public void onCreate(Bundle oldState) {
      super.onCreate(oldState);
      ...
      gameBoard = findViewById(R.layout.gameboard);
      myHandler = new Handler();
      ...
    }
    
    public void onResume() {
      super.onResume();
      displayStartingScreen();
      myHandler.postDelayed(new Runnable() { 
        gotoState1(); 
      }, 250);
    }
    
    private void gotoState1() {
      // It's now 1/4 second since onResume() was called
      displayNextScreen();
      myHandler.postDelayed(new Runnable() { 
        gotoState2();
      }, 250);
    }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question is probably stoopid. But I just don't want to cause
I Have two problem in this Case : I want to pass a JSON
I have this program that is feeding me data. I take this data (string)
I have an arduino program where I want to store data in a dynamic
How to close jQuery thickbox from server side - I want to cause the
well I want to debug some script with Firebug, (cause I can't see anything
I have a list of names that I want to match case insensitive, is
I'm not sure how to target the element I want in this case: var
I have a string: hello good old world and i want to upper case
I am writing a program in C#, and I want to catch exceptions caused

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.