1

I created started a Scheduled task with

Schedule.Every(TimeSpan.FromMinutes(1)).Action("TaskName",TaskMethod);

Now if my saga's Handle() gets invoked by an incoming message which does MarkAsComplete(), the scheduled task that I created does not get cancelled.

How can I cancel the task?

user3344591
  • 567
  • 5
  • 21

1 Answers1

0

From the docs:

When the task is created it is given an unique identifier. The identifier for the task is sent in a message to the Timeout Manager. When it times out and the Timeout Manager returns the message containing the identifier to the endpoint with the scheduled task, the endpoint uses that identifier to fetch and invoke the task from its internal list of tasks.

and

You can look at a scheduled task as a simple never-ending saga

So the task is scheduled at endpoint level - just because you're invoking the task from a saga doesn't mean the task is executing in the same "scope" as the saga.

In the example they give the scheduler is created when the bus starts, presumably to stop only when the host container stops running.

tom redfern
  • 30,562
  • 14
  • 91
  • 126
  • Is there any built in scheduler that will allow me to create a task that I can cancel? Or should I have to use something like Quartz.Net? – user3344591 Jul 01 '14 at 17:04
  • There may be some undocumented way of cancelling a task in NServiceBus, but failing that, yes you should use another scheduler with a richer API. – tom redfern Jul 02 '14 at 07:08
  • The scheduled task is like a simple never-ending saga. If you want your scheduled task to be more complex or end, you can write a full saga with whatever business logic you need. – David Boike Jul 07 '14 at 16:25