[英]how to call a function every x seconds Asynchronously in the background in c++ [duplicate]
我想在我的程序中使用 function 在后台每隔 x 秒检查一次,并且我的基本程序在调用和运行此 function 时不应停止。 我听说过 std::async 和 function settimer() 和 boost.asio 但我很困惑哪一个可以帮助我。 我发现以下代码每 3 秒打印一次“hello”字,但它获得了程序的控制权并且没有在后台运行。
#include <stdio.h>
#include <windows.h>
void CALLBACK f(HWND hwnd, UINT uMsg, UINT timerId, DWORD dwTime)
{
printf("Hello\n");
}
int main()
{
MSG msg;
SetTimer(NULL, 0, 1000 * 3, (TIMERPROC)& f);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.