Search code examples
c++multithreadingmfcsleepthread-sleep

MFC C++ put a 1000 MS sleep on main thread?


Simple enough question I am sure.

Using MFC C++, what header do I need to include and what functions do I need to call to place a 1000 ms sleep on the main thread.

In C# it is easy as Thread.Sleep(1000); so is there something as simple as that in C++?

I am playing a sound and it quits after playing sound. The sound does not get a chance to play for a quits to fast.


Solution

  • As simple as this:

    #include <cstdlib>
    
    std::sleep(1);
    

    Arternatively, under C++11:

    #include <chrono>
    #include <thread>
    
    std::this_thread::sleep_for(std::chrono::seconds(1));