class DelayedAction
{
public:
DelayedAction(int expirePeriod, boost::function<void()> callback):
work(service),
thread(boost::bind(&DelayedAction::run, this)),
timer(service),
m_callback(callback),
m_expirePeriod(expirePeriod)
{}
~DelayedAction()
{
thread.join();
}
void startTimer()
{
}
void on_some_event()
{
startAfter(m_expirePeriod);
}
void stop()
{
timer.cancel();
}
void startAfter(const size_t delay)
{
// no need to explicitly cancel
// timer.cancel();
timer.expires_from_now(boost::posix_time::seconds(delay));
timer.async_wait(boost::bind(&DelayedAction::action, this, boost::asio::placeholders::error));
}
private:
void run()
{
service.run();
}
// ...
void action(const boost::system::error_code& e)
{
if(e != boost::asio::error::operation_aborted)
std::cout << "action" << std::endl;
m_callback();
}
int m_expirePeriod;
boost::function<void()> m_callback;
boost::asio::io_service service;
boost::asio::io_service::work work;
boost::thread thread;
boost::asio::deadline_timer timer;
};
太少信息,以发现问题。显然,SetTimer应该在64位Windows下正常工作。如果没有,则表明存在细微的使用问题。 (由于SetTimer的荒谬复杂性,这并不令人惊讶)。任务不是找到解决方法,而是找到bug。 –
请张贴定义和初始化传递给'SetTimer'四个变量的代码。 –
塞巴斯蒂安雷德尔,我认为你是对的。计时器使用微软thunk为32位,这意味着它不是便携式。 –