Start Mode
Control when TickerQ starts processing jobs in your application.
UseTickerQ
Activate the TickerQ job processor with optional start mode control.
Method:
csharp
IApplicationBuilder UseTickerQ(TickerQStartMode startMode = TickerQStartMode.Immediate);Start Modes
Immediate Start (Default)
TickerQ starts processing jobs immediately when UseTickerQ() is called.
csharp
var app = builder.Build();
// Starts processing jobs immediately
app.UseTickerQ();
app.Run();Behavior:
- Jobs start executing as soon as the application starts
- No manual start required
- Best for most scenarios
Manual Start
TickerQ is configured but doesn't start processing until explicitly started.
csharp
var app = builder.Build();
// Configure but don't start
app.UseTickerQ(TickerQStartMode.Manual);
// Later, start manually
var scheduler = app.Services.GetRequiredService<ITickerQHostScheduler>();
await scheduler.StartAsync();
app.Run();Behavior:
- Jobs are queued but not executed
- Requires explicit start call
- Useful for controlled startup sequences
When to Use Manual Start
Use manual start when:
- You need to perform initialization before jobs run
- Database migrations must complete first
- External services must be ready
- You want to coordinate startup with other systems
- Running in test environments where you control execution
Manual Start Example
csharp
var app = builder.Build();
app.UseTickerQ(TickerQStartMode.Manual);
// Run migrations
await MigrateDatabaseAsync(app.Services);
// Wait for external service
await WaitForExternalServiceAsync();
// Now start TickerQ
var scheduler = app.Services.GetRequiredService<ITickerQHostScheduler>();
await scheduler.StartAsync();
app.Run();Getting the Scheduler Service
csharp
// In Program.cs or Startup
var scheduler = app.Services.GetRequiredService<ITickerQHostScheduler>();
// Start processing
await scheduler.StartAsync();
// Stop processing (if needed)
await scheduler.StopAsync();Checking Scheduler Status
csharp
var scheduler = app.Services.GetRequiredService<ITickerQHostScheduler>();
if (scheduler.IsRunning)
{
Console.WriteLine("TickerQ is processing jobs");
}Lifecycle
Immediate Start Lifecycle
- Application starts
UseTickerQ()called- TickerQ immediately begins processing
- Jobs execute as scheduled
Manual Start Lifecycle
- Application starts
UseTickerQ(TickerQStartMode.Manual)called- TickerQ configured but idle
- Your initialization code runs
scheduler.StartAsync()called- TickerQ begins processing
- Jobs execute as scheduled
Best Practices
- Use Immediate Start for most applications
- Use Manual Start when you need initialization control
- Start as early as possible in manual mode - delays affect job scheduling
- Handle start failures - check if start was successful
Error Handling
csharp
try
{
var scheduler = app.Services.GetRequiredService<ITickerQHostScheduler>();
await scheduler.StartAsync();
if (!scheduler.IsRunning)
{
throw new Exception("TickerQ scheduler failed to start");
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to start TickerQ scheduler");
// Handle startup failure
}See Also
- Scheduler Configuration - Scheduler behavior settings
- Exception Handling - Error handling configuration
- Core Configuration Overview - All core configuration options
