Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Scheduler

This sample illustrates a simple example of the built-in scheduler API. Two common use cases are:

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

The scheduling API is accessed via an 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);
        });

// 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;
        });

Related Articles

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