Poco TimerTask(here https://docs.pocoproject.org/current/Poco.Util.TimerTask.html) and Poco Timer(here https://docs.pocoproject.org/current/Poco.Util.Timer.html) may help. Poco is a library made using the concept of java and c#. Timer provide a cancel function.