Thread: Delay using timeGetTime is too short

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    carpe diem
    Join Date
    Jan 2010
    Posts
    46

    Delay using timeGetTime is too short

    Ok I understand that by trying to create a delay using timeGetTime I'll get an approximate delay, not an exact one. But if anything it should be AT LEAST the amount of time I tell it to delay. My problem is:

    I have one
    printf ("time is: %i", timeGetTime());
    statement before and one after executing the following code. The difference between the first and the second outputs is always much less than 1 sec (usually between 500 and 600 ms)...

    Code:
    int Delay1sec(void)
    {
    	static unsigned long ultime = timeGetTime()+1000;
    	while (timeGetTime()<ultime)
    	{ Sleep(5);	}
    	ultime = timeGetTime()+1000;
    	return 0;
    }
    What am I doing wrong?
    Last edited by doia; 07-16-2010 at 04:15 PM. Reason: typo

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accessing Structures Inside Structures
    By Mellowz in forum C Programming
    Replies: 1
    Last Post: 01-13-2008, 03:55 AM
  2. Help calling function is asm
    By brietje698 in forum C++ Programming
    Replies: 24
    Last Post: 12-06-2007, 04:48 PM
  3. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  4. Say what? - Weird error.
    By Blackroot in forum C++ Programming
    Replies: 6
    Last Post: 08-15-2006, 11:54 PM
  5. Color Variety
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 10-23-2002, 09:17 AM