Async Http Handler

1.1k Views Asked by At

I have a ASHX that do bulk insert at a SQLite. This page load for 2sec +/-

Its a good practice implement it with Async Http Handler to not hold a ASP.NET Thread while I do I/O work.

To turn my IHttpHandler into IHttpAsyncHandler I just did this, its correct?

-Changed interface that I implement at ASHX to IHttpAsyncHandler

-Add this variable and constructor:

readonly Action<HttpContext> process;

public ClassConstructor()
{
    process = ProcessRequest;
}

-Implemented 2 IHttpAsyncHandler methods:

public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
{
    return process.BeginInvoke(context, cb, extraData);
}

public void EndProcessRequest(IAsyncResult result)
{
    process.EndInvoke(result);
}

My main doubt is if I should mantain the original ProcessRequest and just call it with a Action as I did. And if it´s ok to use context.Response inside ProcessRequest, or this work should be done at EndProcessRequest

0

There are 0 best solutions below