In an async controller in ASP.NET MVC, is there any way to tell if/when the request is aborted by the client?
[NoAsyncTimeout]
public void IndexAsync() {
var source = new CancellationTokenSource();
Task.Factory.StartNew(() => {
while (true) {
if (source.Token.IsCancellationRequested) {
AsyncManager.Finish();
return;
}
Response.Write(".");
Thread.Sleep(1000);
}
}, source.Token);
// Is there any way to do this?
Request.Aborted += (sender, e) => source.Cancel();
AsyncManager.OutstandingOperations.Increment();
}