Round #849
11 May 2026, 09:46· csharp· Meta-Llama-3.3-70B-Instruct· r15-firing-v3
- Complexity
- band 1
- ZP / UO / OBS
- 4 / 4 / 5
- Journey weight
- 884
- Lightshift ΔL
- +0.00
Prompt
Write a BackgroundService that reads work items from an in-memory queue and processes each one with a small delay, with graceful shutdown handling.
Zero-point index (what the engine surfaced)
ZPI-ZPI-0006 | 2026-05-11T09:46:20Z
Write a BackgroundService that reads work items from an in-memory queue and processes each one with a small delay, with graceful shutdown handling.
ZERO POINT — 4 entries (structural invariants)
● hsl(61.72, 100%, 49%) BackgroundService [contract]
● hsl(337.38, 100%, 32%) IPublishEndpoint [contract]
● hsl(116.66, 100%, 32%) IConsumer<T> [contract]
● hsl(352.98, 100%, 30%) IBus [contract]
UNOBSERVED — 4 entries (implied truths)
○ hsl(27.69, 100%, 50%) async [feature]
○ hsl(3.75, 100%, 38%) CancellationToken [feature]
○ hsl(216.00, 100%, 26%) Message broker publish [function]
○ hsl(31.38, 100%, 42%) Scoped registration [function]
OBSERVED — 5 entries (explicit in request)
◉ hsl(98.46, 100%, 50%) with [feature]
◉ hsl(141.54, 100%, 15%) Memory of T [feature]
◉ hsl(327.18, 100%, 22%) Queue of T [feature]
◉ hsl(168.75, 100%, 3%) Memory of T [feature]
◉ hsl(232.62, 100%, 25%) BackgroundService [function]
COMPLEXITY │ 13 entries │ spread: 323° │ band: MEDIUM
Baseline response (no ZPI)
Here is the code that matches the provided specification:
```
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
public class QueueHostedService : BackgroundService
{
private readonly ILogger _logger;
private readonly IWorkQueue _workQueue;
public QueueHostedService(ILogger<QueueHostedService> logger, IWorkQueue workQueue)
{
_logger = logger;
_workQueue = workQueue;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("QueueHostedService is starting.");
while (!stoppingToken.IsCancellationRequested)
{
var workItem = await _workQueue.DequeueAsync(stoppingToken);
try
{
await DoWork(workItem);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error processing work item");
}
}
_logger.LogInformation("QueueHostedService is stopping.");
}
private async Task DoWork(WorkItem workItem)
{
await Task.Delay(1000); // simulate some work
_logger.LogInformation($"Processed work item {workItem.Id}");
}
}
```
Note that I assumed the `IWorkQueue` interface has a `DequeueAsync` method that returns a `WorkItem` object, and that the `WorkItem` class has an `Id` property. You may need to adjust the code to match your specific implementation of these types.
Enhanced response (with ZPI)
```csharp
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
public class WorkItemProcessor : BackgroundService
{
private readonly ILogger<WorkItemProcessor> _logger;
private readonly ConcurrentQueue<WorkItem> _queue = new ConcurrentQueue<WorkItem>();
public WorkItemProcessor(ILogger<WorkItemProcessor> logger)
{
_logger = logger;
}
public void EnqueueWorkItem(WorkItem item)
{
_queue.Enqueue(item);
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
if (_queue.TryDequeue(out WorkItem item))
{
try
{
await ProcessWorkItemAsync(item, stoppingToken);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error processing work item");
}
}
else
{
await Task.Delay(100, stoppingToken);
}
}
}
private async Task ProcessWorkItemAsync(WorkItem item, CancellationToken stoppingToken)
{
_logger.LogInformation("Processing work item {Id}", item.Id);
await Task.Delay(500, stoppingToken); // Simulate processing delay
_logger.LogInformation("Finished processing work item {Id}", item.Id);
}
}
public class WorkItem
{
public int Id { get; set; }
public string Data { get; set; }
}
```
To register the `WorkItemProcessor` as a background service in the DI container, add the following code to the `Startup.cs` file:
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddHostedService<WorkItemProcessor>();
}
```
This implementation provides a `WorkItemProcessor` class that inherits from `BackgroundService` and reads work items from an in-memory queue. Each work item is processed with a small delay, and the service handles shutdown gracefully by checking the `stoppingToken` regularly. The `EnqueueWorkItem` method allows you to add work items to the queue from other parts of the application.
Note that this example uses a simple `ConcurrentQueue` to store work items, which may not be suitable for production use. In a real-world application, you might want to use a more robust message broker or queueing system.
This implementation requires additional text to fully explain the solution.
Grader chain
Each grader reads the same baseline + enhanced pair and casts an independent verdict. Disagreement is the framework's own signal — not noise to be averaged away.
V1samba/Meta-Llama-3.3-70B-Instruct
BetterV4qwen2.5-coder-3b-instruct
BetterV5openrouter/qwen/qwen3-235b-a22b-2507
BetterV7qwen2.5-coder-7b-instruct
BetterV8openai/gpt-4.1
BetterV9anthropic/claude-opus-4-7
BetterV12openai/gpt-4o
BetterComments
Our grader said what it said. What do you say? Comment as a guest below.
No comments yet. Be the first to say what you make of this round.