That’s one thing I don’t miss from the lack of threading support… don’t sleep() in threaded programs unless you absolutely have no other choice (wait handles, mutexes, and such).
Anyway, if you really need to pause for a certain amount of time, you could use a timer:
#include <chrono>
const auto endTime = std::chrono::steady_clock::now() + std::chrono::milliseconds(1000);
while (endTime > std::chrono::steady_clock::now()) { /* do nothing */ }
Well, the module is single-threaded, so that’s to be expected. You’d have the same result with sleep().
What does your standalone module do that isn’t triggered from the dispatch handler originally? For any concurrency to happen there would need to be some kind of “external” trigger like another callback happening at the same time, and AFACT there’s only the init/deinit and the SimConnect message dispatcher which call anything within the module.
Nothing from std concurrency lib is available… no thread, mutexes, atomics, wait handles, etc. And since Win32 isn’t supported either, that means no corresponding MSVC features or timers.
you can create your own message timer service even in a single thread…
create a timer event once a second or once every x seconds … set variable int to coundDown seconds sleeping when you want a sleep period
= increment a timer counter of seconds
2 if there are any timer sleep/wake alerts active decrement the count by 1 (such wakeTimer1Seconds, wakeTimer2Seconds ) (watcher)
= send my self a message (“sleep” (do nothing) but wake in 2 seconds) (set wakeTimer1Seconds = 2
if a wake counter <= 0 then end sleep state end
if you do any other actions (keyboard , mouse) during the sleep , then set sleep to 0 to turn off watcher
After some tests and unsuccessful attempts, at least as far as I know there is no way to create timers inside the sim, as indicated by @Maxinal6379, no threads or anything that can handle independent cycles.
I have also solved my problem using Simconnect Callbacks, and although my module does not need to use Simconnect, I created a timer with a dummy callback and some counters.