Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 730 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sleep function in Windows, using C

#1
I need to sleep my program in Windows. What header file has the sleep function?
Reply

#2
[MSDN][1]: Header: Winbase.h (include Windows.h)


[1]:

[To see links please register here]

Reply

#3
`SleepEx` function (see

[To see links please register here]

) is the best choise if your program directly or indirectly creates windows (for example use some COM objects). In the simples cases you can also use `Sleep`.
Reply

#4
Use:

#include <windows.h>

Sleep(sometime_in_millisecs); // Note uppercase S

And here's a small example that compiles with [MinGW][1] and does what it says on the tin:

#include <windows.h>
#include <stdio.h>

int main() {
printf( "starting to sleep...\n" );
Sleep(3000); // Sleep three seconds
printf("sleep ended\n");
}

[1]:

[To see links please register here]

Reply

#5
Include the following function at the start of your code, whenever you want to busy wait. This is distinct from sleep, because the process will be utilizing 100% cpu while this function is running.

void sleep(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock())
;
}

Note that the name `sleep` for this function is misleading, since the CPU will not be sleeping at all.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through