In a ASP.NET applciation there are possibly many requests coming in at any one time. For each of these requests the framework is utilising a HttpHandler instance to process the request.
By making a httpHandler "reusable" you are flagging that the same instance of the handler can be used on another request.
This reduces the load as each request does not have to have a unique instanced HttpHandler.
For example:
public class MyHttpHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.Write("hello");
}
public bool IsReusable
{
get { return true; }
}
}
There is no need to have individual httphandlers in this scenario as it performs the same operation regardless of what request is using it.
However, you have to make sure that your httphandler is thread-safe if you want it be re-usable.
This is not thread-safe for example:
public class MyHttpHandler : IHttpHandler
{
protected responseString;
public void ProcessRequest(HttpContext context)
{
responseString = HttpContext.Current.Session["value"].ToString();
context.Response.Write("hello");
}
public bool IsReusable
{
get { return true; }
}
}
The problem here is that if let's say 2 requests are using this httphandler at the exact same time, one could set the session variable to the internal string and just as it is about to write it out, a context switch happens and the second one assigns its session variable to the string.... when context switches back to the original thread.. the value is now totally different.
If you aren't sure, basically set it to false - this does increase memory for each request, but ensures your handler performs correctly.