13

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?

Josh Stodola
  • 81,538
  • 47
  • 180
  • 227
  • 2
    possible duplicate of [Significance of bool IsReusable in http handler interface](http://stackoverflow.com/questions/539302/significance-of-bool-isreusable-in-http-handler-interface) – svick Mar 01 '12 at 12:51

3 Answers3

14

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.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • The handler is fairly simple, and it does nto need to maintain state. It should be thread safe. So I think I can set it to true! Thank you. – Josh Stodola Jan 13 '10 at 15:03
  • 1
    When you have private member variables in the handler and make use of the context is this threadsafe? – cpt.oneeye Aug 31 '12 at 18:22
  • Can you please explain **because the ProcessRequest method might be invoked from multiple threads at the same time.** ? –  May 24 '13 at 05:20
3

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.

Klaus Byskov Pedersen
  • 117,245
  • 29
  • 183
  • 222
3

IsReusable keeps the handler in memory and able to handle multiple requests. When set to false, it has to create a new instance of the handler for each incoming request.

I had some issues with this property myself:

Streaming Databased Images Using HttpHandler

Community
  • 1
  • 1
IrishChieftain
  • 15,108
  • 7
  • 50
  • 91