class Thread : public main_thread_callback
{
public:
virtual void callback_run()
{
// This function is being regularly called.
// I use this function to poll data from an external input device
}
};
class Timer
{
public:
void start() { mThread = CreateThread(0, 0, &Timer::run, 0, 0, mThreadId); }
void stop() { TerminateThread(mThread, 0); }
private:
LPDWORD mThreadId;
HANDLE mThread;
static DWORD WINAPI run(void*)
{
while(true)
{
Sleep(1000); // Call interval of the callback_run function
service_ptr_t<Thread> p_callback = new service_impl_t<Thread>();
static_api_ptr_t<main_thread_callback_manager> man;
man->add_callback(p_callback);
}
}
};
class Application : public initquit
{
public:
virtual void on_init() { mTimer.start(); }
virtual void on_quit() { mTimer.stop(); }
private:
Timer mTimer;
};
static initquit_factory_t<Application> foo_initquit;
SetTimer might work. Havn't used that one so I'm not sure. But as you see in this stripped-down code I got a callback to callback_run each 1000 ms. Thats what I want, and it works great!