<div dir="ltr">It looks like my problems aren't with the timer at all. This listing pretty much mimicked example 3.<div>It ends up that my problem is that if you click on a console window in windows 10, the program ceases execution when it enters "quick edit" mode. I was not aware of that new behavior and thought the timer was not working. The program run fine, as is, if you don't touch the mouse.<br><br>Sorry, false alarm.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 11, 2019 at 7:42 PM Christopher Pisz <<a href="mailto:christopherpisz@gmail.com">christopherpisz@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I am trying to perform a task on an interval and I made a POC using boost::asio::steady_timer. When I debug it, it only performs the callback once and does not fire again. I am not sure what I am doing wrong. Any suggestions?<div><br></div><div> // DoMouseEvents.cpp : This file contains the 'main' function. Program execution begins and ends there.<br> //<br><br> #include <boost/asio.hpp><br> #include "boost/asio/deadline_timer.hpp"<br> #include<boost/bind.hpp><br> #include <chrono><br> #include <iostream><br><br> class Pooper<br> {<br> boost::asio::io_context & m_ioContext;<br> boost::asio::steady_timer m_timer;<br><br> public:<br> Pooper(boost::asio::io_context & ioContext)<br> :<br> m_ioContext(ioContext)<br> , m_timer(boost::asio::steady_timer(ioContext))<br> {<br> }<br><br> void Run()<br> {<br> m_timer.expires_from_now(std::chrono::seconds(5));<br> m_timer.async_wait(boost::bind(&Pooper::OnTimerExpired, this, boost::asio::placeholders::error));<br> }<br><br> void OnTimerExpired(const boost::system::error_code & error)<br> {<br> if (error.failed())<br> {<br> std::cerr << "boost error: Failed" << std::endl;<br> }<br><br> std::cout << "Poop" << std::endl;<br><br> try<br> {<br> // Move the mouse<br> int x = 500;<br> int y = 500;<br> if (!::SetCursorPos(x, y))<br> {<br> int errorCode = GetLastError();<br> std::cerr << "SetCursorPos error: " << errorCode << std::endl;<br> }<br><br> // Left button down<br> x = 65536 * 500;<br> y = 65536 * 500;<br> ::mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN, x, y, NULL, NULL);<br><br> // Left button up<br> x = 65536 * 500;<br> y = 65536 * 500;<br> ::mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP, x, y, NULL, NULL);<br><br> m_timer.expires_from_now(std::chrono::seconds(5));<br> m_timer.async_wait(boost::bind(&Pooper::OnTimerExpired, this, boost::asio::placeholders::error));<br> }<br> catch (std::exception &)<br> {<br> std::cerr << "An exception occured." << std::endl;<br> }<br> }<br> };<br><br> int main()<br> {<br> boost::asio::io_context ioContext;<br> auto pooper = Pooper(ioContext);<br> pooper.Run();<br> ioContext.run();<br><br> std::cerr << "Exited..." << std::endl;<br> }<br><br></div></div> </blockquote></div>