locked
Is there a supported API in Metro for replacing "Sleep" ?

Answers

  • @Chik

    The API list you reviewed are the allowed list of API's that will pass the Windows App Certification Kit. As SimonRev mentioned, you would not want to block on the UI thread so consider the timer approach mentioned. If you have a desire to wait for an event on a background thread, then you might consider the WaitFor___Object APIs on that list as well.

     

    If this is STRICTLY for development testing then you will find that you can still use Sleep (#include "windows.h") but it will NOT pass certification for the Store. It will compile and cause whatever trouble you desire on a background or UI thread. Make certain it is removed prior to releasing your app.

     

    Thanks,

    -David

    • Marked as answer by Bob_Bao Tuesday, December 27, 2011 7:58 AM
    Tuesday, December 13, 2011 2:56 AM
    Moderator
  • Dear all,

      Thanks for your replies.

      Currently I create an inline function which uses SleepConditionVariableCS with meaningless condition variable and critical section to replace the original Sleep function, and it works. 

      This may be a temp solution. Hope it help for others having the same problem.

    Thanks.

    Chik

    • Marked as answer by Bob_Bao Tuesday, December 27, 2011 7:58 AM
    Wednesday, December 14, 2011 2:42 AM

All replies

  • I don't actually know the answer, but if you look at the way the metro API was designed -- any function that can potentially block for more than just a couple of milliseconds was converted to an asynchronous function with no synchronous equivalent.  That, to me, is a pretty strong hint that they don't want us sleeping.  And truly, sleeping in the UI thread would be a disaster the way things are designed.

    If I were to take a guess, I suspect that the supported approach would be to create a dispatch timer and just put the code you want to execute after the sleep in a lambda that executes when the timer fires. (Although there may be a more elegant approach that I cannot think of off the top of my head).  With this in mind, it should be fairly easy to write a Sleep function that takes a time and a std::function completion routine)

    Monday, December 12, 2011 1:40 PM
  • @Chik

    The API list you reviewed are the allowed list of API's that will pass the Windows App Certification Kit. As SimonRev mentioned, you would not want to block on the UI thread so consider the timer approach mentioned. If you have a desire to wait for an event on a background thread, then you might consider the WaitFor___Object APIs on that list as well.

     

    If this is STRICTLY for development testing then you will find that you can still use Sleep (#include "windows.h") but it will NOT pass certification for the Store. It will compile and cause whatever trouble you desire on a background or UI thread. Make certain it is removed prior to releasing your app.

     

    Thanks,

    -David

    • Marked as answer by Bob_Bao Tuesday, December 27, 2011 7:58 AM
    Tuesday, December 13, 2011 2:56 AM
    Moderator
  • Dear all,

      Thanks for your replies.

      Currently I create an inline function which uses SleepConditionVariableCS with meaningless condition variable and critical section to replace the original Sleep function, and it works. 

      This may be a temp solution. Hope it help for others having the same problem.

    Thanks.

    Chik

    • Marked as answer by Bob_Bao Tuesday, December 27, 2011 7:58 AM
    Wednesday, December 14, 2011 2:42 AM
  • I'm having this issue. Can you give an example of what you ended up with?
    • Proposed as answer by Halalbaro Wednesday, January 02, 2013 3:34 PM
    Tuesday, December 25, 2012 2:32 AM