0

我有这个可调用的计时器,但是在使用 Windows 窗体时 std::threads 不可用

class Timer
{
public:
    template <class callable, class... arguments>
    Timer(int after, bool async, callable&& f, arguments&&... args)
    {
        std::function<typename std::result_of<callable(arguments...)>::type()> task(std::bind(std::forward<callable>(f), std::forward<arguments>(args)...));

        if (async)
        {
            std::thread([after, task]() {
                std::this_thread::sleep_for(std::chrono::milliseconds(after));
                task();
            }).detach();
        }
        else
        {
            std::this_thread::sleep_for(std::chrono::milliseconds(after));
            task();
        }
    }

};

有没有人可以替代它?

4

1 回答 1

0

通过将计时器和使用它的 cpp 文件设置为不受管理,我无论如何都可以使用此计时器。更多关于这里

于 2018-01-20T20:29:53.270 回答