Scheduling

Component: NServiceBus
NuGet NServiceBus (6.x)

This sample illustrates a simple use of the Scheduling API. Two common use cases are shown

  1. Sending a message.
  2. Executing some custom code.

The scheduling API is accessed via in instance of IEndpointInstance.

// Send a message every 5 seconds
await endpointInstance.ScheduleEvery(
        timeSpan: TimeSpan.FromSeconds(5),
        task: pipelineContext =>
        {
            var message = new MyMessage();
            return pipelineContext.SendLocal(message);
        })
    .ConfigureAwait(false);

// Name a schedule task and invoke it every 5 seconds
await endpointInstance.ScheduleEvery(
        timeSpan: TimeSpan.FromSeconds(5),
        name: "MyCustomTask",
        task: pipelineContext =>
        {
            log.Info("Custom Task executed");
            return Task.CompletedTask;
        })
    .ConfigureAwait(false);

Related Articles

  • Scheduling
    Schedule a task or an action/lambda, to be executed repeatedly at a given interval.

Last modified