<%@ WebHandler Language="C#" Class="Handler" %>
using System.Threading.Tasks;
public class Handler : IHttpAsyncHandler
public void ProcessRequest(HttpContext context)
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
var getTask = Work(context);
var tcs = new TaskCompletionSource<object>(context);
getTask.ContinueWith((t, o) =>
if (t.Exception != null) tcs.SetException(t.Exception.InnerExceptions);
public void EndProcessRequest(IAsyncResult result)
var con = t.AsyncState as HttpContext;
if (con != null) con.Response.Write("error");
public async Task Work(HttpContext context)
throw new AggregateException();
context.Response.Write("aaaaaa");