Feb 23 2026
Results.ServerSentEvents. This makes real-time streaming in ASP.NET Core simpler, cleaner, and more aligned with HTTP semantics.
text/event-stream content type and continuously sends messages as events occur.
IAsyncEnumerable<T> directly to a browser using native HTTP infrastructure. With .NET 10, this is now handled by Results.ServerSentEvents, which abstracts away manual header configuration, formatting, and flushing logic.
public enum OrderStatus { Created, PaymentConfirmed, Packed, Shipped, OutForDelivery, Delivered } public sealed record OrderStatusUpdate( Guid OrderId, OrderStatus Status, DateTime Timestamp);
System.Threading.Channels is ideal for this scenario.
IAsyncEnumerable<T>, which is exactly what Results.ServerSentEvents expects.
public sealed class OrderStreamService { private readonly ConcurrentDictionary<Guid, Channel<OrderStatusUpdate>> _streams = new(); public ChannelReader<OrderStatusUpdate> Subscribe(Guid orderId) { var channel = Channel.CreateUnbounded<OrderStatusUpdate>(); _streams[orderId] = channel; return channel.Reader; } public async Task PublishAsync(OrderStatusUpdate update) { if (_streams.TryGetValue(update.OrderId, out var channel)) { await channel.Writer.WriteAsync(update); } } public void Unsubscribe(Guid orderId) { if (_streams.TryRemove(orderId, out var channel)) { channel.Writer.TryComplete(); } } }
app.MapGet("/orders/{orderId:guid}/stream", ( Guid orderId, OrderStreamService streamService, CancellationToken cancellationToken) => { var reader = streamService.Subscribe(orderId); return Results.ServerSentEvents( reader.ReadAllAsync(cancellationToken), eventType: "order-update"); });
Results.ServerSentEvents automatically:Content-Type to text/event-stream
FlushAsync.
app.MapPost("/orders/{orderId:guid}/simulate", async ( Guid orderId, OrderStreamService streamService) => { var statuses = Enum.GetValues<OrderStatus>(); foreach (var status in statuses) { await Task.Delay(2000); await streamService.PublishAsync(new OrderStatusUpdate( orderId, status, DateTime.UtcNow)); } return Results.Ok("Order simulation completed."); });
https://localhost:7060/orders/{orderId}/simulate

https://localhost:7060/orders/{orderId}/stream
Results.ServerSentEvents, Server-Sent Events in .NET 10 have become a first-class feature in ASP.NET Core.
1. Design Patterns that Deliver
This isn’t just another design patterns book. Dive into real-world examples and practical solutions to real problems in real applications.Check out it here.
Go-to resource for understanding the core concepts of design patterns without the overwhelming complexity. In this concise and affordable ebook, I've distilled the essence of design patterns into an easy-to-digest format. It is a Beginner level. Check out it here.
Every Monday morning, I share 1 actionable tip on C#, .NET & Arcitecture topic, that you can use right away.
Join 18,000+ subscribers to improve your .NET Knowledge.
Subscribe to the TheCodeMan.net and be among the 18,000+ subscribers gaining practical tips and resources to enhance your .NET expertise.
Powered by EmailOctopus