The sample code looks long, but actually it\'s not so complicated :-)
What I\'m trying to do is, when a user calls EventTimer.Start(), it will execute the callba
As Sam hinted, depending on what you're attempting to accomplish, most of the time it is considered a design error to stop an io_service. You do not need to stop()
/reset()
the io_service in order to reschedule a timer.
Normally you would leave a thread or thread pool running attatched to an io_service
and then you would schedule whatever event you need with the io_service
. With the io_service
machinery in place, leave it up to the io_service
to dispatch your scheduled work as requested and then you only have to work with the events or work requests that you schedule with the io_service
.
I figured it out, but I don't know why that I have to put io.reset()
in Start()
, since it's already been called in Stop().
See the updated code in the post.
It's not entirely clear to me what you are trying to accomplish, but there's a couple of things that are incorrect in the code you have posted.
io_service::reset()
should only be invoked after a previous invocation of io_service::run()
was stopped or ran out of work as the documentation describes.Sleep()
, the call to io_service::run()
will block as long as it has work to do.