Skip to content

Instantly share code, notes, and snippets.

View SteveDunn's full-sized avatar

Steve Dunn SteveDunn

View GitHub Profile
@SteveDunn
SteveDunn / detect_disconnect.cs
Last active May 4, 2022 10:34
WebApi client disconnection
[HttpGet(Name = "GetWeatherForecast")]
public async Task<IEnumerable<WeatherForecast>> Get()
{
//pass this around to long running tasks
CancellationToken cancellationToken = HttpContext.RequestAborted;
if (cancellationToken.IsCancellationRequested)
{
throw null!; // or whatever you want to do
}
return await DoItSlowly(++_callerCount, cancellationToken);