Run your first job.

Flywheel supports several storage mechanisms. This guide uses Redis as one option. To follow this example, use .NET 10 and Redis 6.0.9 or newer.

1. Create an app

dotnet new web -n FlywheelExample
cd FlywheelExample
dotnet add package Soenneker.Flywheel.Core
dotnet add package Soenneker.Flywheel.Redis
dotnet add package Soenneker.Flywheel.Generators

Add PrivateAssets="all" to the Generators package reference in your project file. Start Redis at localhost:6379, or update the connection string below.

2. Define and enqueue a job

Replace Program.cs with:

using Soenneker.Flywheel.Core.Attributes;
using Soenneker.Flywheel.Core.Registrars;
using Soenneker.Flywheel.Core.Services.Abstract;
using Soenneker.Flywheel.Generated;
using Soenneker.Flywheel.Redis;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddFlywheel(options => options.Workers = 4)
    .AddRedis(options => options.ConnectionString = "localhost:6379")
    .AddGeneratedJobs();

var app = builder.Build();
var client = app.Services.GetRequiredService<IJobClient>();

await client.Enqueue(FlywheelJobs.MessageJobs_Write,
    new Message("Hello from Flywheel"));

await app.RunAsync();

public sealed record Message(string Text);

public sealed class MessageJobs(ILogger<MessageJobs> logger)
{
    [FlywheelJob("message.write.v1")]
    public Task Write(Message message, CancellationToken cancellationToken)
    {
        logger.LogInformation("{Message}", message.Text);
        return Task.CompletedTask;
    }
}

The source generator creates FlywheelJobs and typed invokers at build time. Dispatch calls your job method directly, without runtime reflection.

3. Run it

dotnet run

Look for “Hello from Flywheel” in the console. Enqueue saves the job to your configured storage; a background worker executes it. In your application services, inject IJobClient to submit work.

Jobs can run more than once. Make handlers safe to retry and pass cancellation tokens through to async work.

Next steps

Add the dashboard to search jobs and inspect executions. Continue to Advanced usage for workflows, schedule management, execution controls, and reliability.