Getting Started
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Previews
Samples

Scheduler

Component: NServiceBus
NuGet Package: NServiceBus (8-pre)
This page targets a pre-release version. Pre-releases are subject to change and samples are not guaranteed to be fully functional.

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

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

// 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.

Last modified