I have an IHttpHandler that I think can benefit from reuse because it is expensive to set up and is thread safe. But for each request a new handler is created. My handler is not reused.
Below is my simple test case without expensive setup. This simple case demonstrates my problem:
public class MyRequestHandler : IHttpHandler
{
int nRequestsProcessed = 0;
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
nRequestsProcessed += 1;
Debug.WriteLine("Requests processed by this handler: " + nRequestsProcessed);
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
}
Requests processed by this handler: 1
Requests processed by this handler: 1
Requests processed by this handler: 1
Requests processed by this handler: 1... at least 100 times. I never see > 1.
I don’t understand how IsReusable works? Is there anything else that reuse can defeat? My handler is called from a Silverlight application, if that matters.
source
share