Cancellation Token Implementation

Trying to implement cancellation of tasks in a project and having a few problems understanding how the cancellation tokens actually work. I’m passing them into my methods and checking at different points along the way with token.ThrowIfCancellationRequested()

How do I actually cancel the job? I’ve had a bit of luck with deleting the job through the BackgroundJobClient.Delete(jobId) method, which seems to cause the OperationCanceledException, although this then marks the task deleted which is not quite what I wanted as I want these to be re-queue-able.

In short:

  1. Is there a way to cancel a job without deleting it?
  2. If not, are there plans to implement this?
  3. Am I even doing the right thing by using the Delete method to ‘cancel’ tasks?

Hoping for an answer to this as well. Just dipping my toes into Hangfire as a replacement for our homegrown job processor. Task progress monitoring and cancellation (quitting n items into a 100,000 item batch job) is a definite requirement for me.