A current C# project of mine required a timer where every couple of seconds a method would fire and a potentially fairly long-running process would...
For further actions, you may consider blocking this person and/or reporting abuse
How would you handle a cancellation token? I have a need for a timer that should stop firing on cancellation and also the DoWork method should immediately quit.
Hi Katie,
Take a look at this. hitting ctrl-c while its running or in the 5-second DoWork method will cancel gracefully and hopefully do what you want.
I plan to blog about it in more detail later but this should help.
Gist here
gist.github.com/solrevdev/f28ab813...
Thanks John. I see now the running timer callback is buried several levels down. Makes things a bit more complex, but I understand what you did.
Ahh yes, the timer's TimerCallback method signature needed to be
void DoWork(object state)
hence needing another method call that uses async Task accepting a CancellationToken.But looking at it again I think that
DoWorkAsync
andRunJobAsync
could just be the one method.I'll take another look later and will try and explain more in another blog post.
Great! Looking forward to it.