Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I set IsReusable to True in my HttpHandlers?

I've never fully understood this property of the IHttpHandler. It is a property that you have to set when you implement the interface. I've assumed that setting it to true would be better for performance, but I am not sure what the negative side effects might be. Should I return true or false?

like image 335
Josh Stodola Avatar asked Jan 13 '10 14:01

Josh Stodola


2 Answers

It is used to indicate if a single instance of the IHttpHandler will be used to process multiple concurrent requests. So if you set it to true it will improve performance but you must make sure that your code is thread safe because the ProcessRequest method might be invoked from multiple threads at the same time.

like image 167
Darin Dimitrov Avatar answered Nov 07 '22 14:11

Darin Dimitrov


If your IHttpHandler implementation contains state (perhaps setup in the constructor and later used in ProcessRequest) then it can sometimes be useful to set IsReusable to false.

like image 3
Klaus Byskov Pedersen Avatar answered Nov 07 '22 12:11

Klaus Byskov Pedersen