0

这是在后台调用更新功能的方法吗?我需要每 5 秒更新一次集合。

在 C# 中,我创建了计时器集开始停止和委托,它可以工作。

在 C++ 中存在任何方式吗?

4

2 回答 2

2

C++11:

#include <thread>

void update() {
    for (;;) {
        do_update();
        this_thread::sleep_for(std::chrono::seconds(5));
    }
}

int main() {
    std::thread thr(update);
    thr.detach();
    // do whatever the program needs to do
    return 0;
}
于 2013-05-12T19:34:41.203 回答
1

在我们的嵌入式系统上,我们创建了一个在后台运行的单独任务。另一种方法是通过中断完成大部分工作,非中断代码将在后台运行。

我想这取决于平台,您使用的是哪个平台?

于 2013-05-12T18:48:19.580 回答