Should I set IsReusable to True in my HttpHandlers?

馋奶兔 提交于 2019-12-03 11:14:23

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.

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.

IrishChieftain

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!