0

I have this callable timer, but the std::threads are not not available when working with Windows forms

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();
        }
    }

};

Any one have an alternative to it?

1 Answers1

0

Bysetting the timer and the cpp file using it to be unmanaged, i was able to use this timer anyway. more about that here