Sleep() function windows 8 c++

12,995

Solution 1

You shouldn't be including Synchapi.h directly. Include Windows.h instead.

#include <Windows.h>

int main()
{
  Sleep(1000);
  return 0;
}

Solution 2

Are you using C++11? If you are you can use:

#include <thread>
template< class Rep, class Period >
void sleep_for( const std::chrono::duration<Rep,Period>& sleep_duration );

Update The Sleep() function is only available for Desktop Apps. Are you building a formerly known as Metro app? Or an App Store app? See this article for some work arounds:

http://blogs.msdn.com/b/win8devsupport/archive/2012/11/28/introduce-multi-thread-programming-in-windows-store-apps-part-ii.aspx

Share:
12,995
nat1707828
Author by

nat1707828

Updated on June 04, 2022

Comments

  • nat1707828
    nat1707828 over 1 year

    I'm attempting to get the Sleep() function working on a Windows 8 operating system, with c++. So far I haven't found any examples specific to this.

    Following from http://msdn.microsoft.com/en-us/library/windows/desktop/ms686298%28v=vs.85%29.aspx i've included the header <Synchapi.h>, though i get "Identifier "Sleep" is undefined". I am able to find the functions SleepConditionVariableCS() and SleepConditionVariableSRW() from Synchapi.h, but not Sleep().

    Has anyone managed to use Sleep() on a Windows 8 operating system or know why I am unable to find the function?