Mar*_*ker 5 c# asp.net silverlight
我有一个IHttpHandler,我相信它可以从重用中受益,因为它设置起来很昂贵,并且是线程安全的.但是正在为每个请求创建一个新的处理程序.我的处理程序没有被重用.
以下是我的简单测试用例,没有昂贵的设置.这个简单的案例说明我的问题:
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.
Run Code Online (Sandbox Code Playgroud)
我误解了IsReusable的工作原理吗?还有其他东西可以打败重复使用吗?我的处理程序是从Silverlight应用程序调用的,如果这有任何区别的话.
| 归档时间: |
|
| 查看次数: |
390 次 |
| 最近记录: |