title: How to use boost's deadline_timer::asynch_wait in a loop?
body: <p>I'm having a MFC application (VC10) where I'm using  deadline_timer::asynch_wait() running in a while-loop in a separated thread. Due to fact, the waiting period can be some minutes or even more, I'm using asych_wait to able to interrupt the wait. My problem is that the timer callback is called only once, while the first execution. When the loop executes for the second time, the callback isn't called any more. Any idea what I'm doing wrong? </p>
  
  <pre><code>header:
  std::unique_ptr&lt;boost::asio::deadline_timer&gt; m_timer;
  
  cpp:
  UINT camThread1( LPVOID pParam )
  {
    CDlg* pView = (CMyDlg*) pParam;
    boost::asio::io_service io_service;
  
    // to be able to interrupt the timer from the GUI Thread
    pView-&gt;m_timer.reset(new boost::asio::deadline_timer(io_service)); 
  
    boost::posix_time::ptime lastLoop;
    typedef boost::asio::time_traits&lt;boost::posix_time::ptime&gt; time_traits_t;
    lastLoop = time_traits_t::now();
  
    while (1)
    {
      boost::posix_time::ptime nextFrameTime;
      // calculate the time to wait
      nextFrameTime = lastFrameTime + boost::posix_time::seconds(pView-&gt;m_interval);
  
      // start the timer
      pView-&gt;m_timer-&gt;expires_at(nextFrameTime);
      pView-&gt;m_timer-&gt;async_wait(boost::bind(&amp;CDlg::timer_handler, pView, boost::asio::placeholders::error));
      io_service.run();
  
      DWORD dwWaitResult = WaitForSingleObject(pView-&gt;m_timerEvent, INFINITE);
      switch (dwWaitResult) 
      {
        // check results
      }
      lastLoop = time_traits_t::now(); // get the current time
  
      // do something
    }
  }
  </code></pre>
  
  <p>My timer callback looks as follows:</p>
  
  <pre><code>void CDlg::timer_handler(const boost::system::error_code&amp; error)
  {
    if (!error || error == boost::asio::error::operation_aborted)
    {
      SetEvent(m_timerEvent);
    } else {
      //throw std::exception(...);
    }
  }
  </code></pre>
  
  <p>My Event is created as follows:</p>
  
  <pre><code>m_timerEvent = CreateEvent( NULL, FALSE, FALSE, TEXT("timerEvent"));
  </code></pre>
  
  <p>Any suggestion? please...</p>
  
  <p>Tnx in advance &amp; cheers
  greg </p>