如何解释这个ASP.NET的IsClientConnected奇怪的现象?

 

因为我post到msdn了,想问问为什么,所以开始用鸟文写的。见谅。我鸟文实在不好。就不删了。

 

try this code, set two breakpoint at the red text.
先在vs里面试试写下面的这个代码,两个红色的是两个断点,别忘了加上。

 

class HelloWorldHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.Clear();

           //在这个断点触发的时候关上浏览器噢!You must close your browser at this breakpoint,
            context.Response.OutputStream.Write(new byte[]{1}, 0, 1);
            context.Response.Flush();
            var x = context.Response.IsClientConnected;
            //这个时候你发现x是false,如果你看到x=false了那么下面你就能重现我看到的东西了,也就是这个线程不被销毁。 When The x is false then step over next, you will see the thread in server do not destroy.,
            context.Response.End();
        }
        public bool IsReusable
        {
            get
            {
                return true;
            }
        }
    } 


 ----------------

 In order to keep the asp.net development server running ,I use chrome. of course, you can use IE to test this code, if you can keep asp.net development server running when close the IE window.

 

 因为我用ie做debugger的时候每次关上ie那个什么asp.net development server就跟着关了,让我很光火。于是,在vs上面随便找个文件aspx的吧,点右键,点browse with..选择用chrome做默认的debugger,用这个的好处就是每次关了

chrome 你还能监视到asp.net development server的线程。嗯。就这么点作用。要不我就用ie了。

 

OK, then we need a program to monitor the thread of the asp.net development server , so i use NetLimiter 2 Pro,

然后就是还需要用一个线程监视器,其实用什么无所谓,正好我装了一个netlimiter 2 pro这个就能监视线程了,就用这个了。

 

You can use any other software to monitor the thread of the asp.net development server .

 当然也可以用其他软件监视asp.net development server

 

Ok , follow me ,let's go test1.

 好了开始测试1。

 

1,First, press f5 to Debug. then the chrome window show, vs2008 break at first breakpoint,

1,首先按f5来调试,等到第一个断点触发的时候,把chrome关了。

2,Close the chrome window!

2,对,第一个断点出发的时候关了那个浏览器窗口

3.back to vs2008, press f10 to step over until the next breakpoint

3,然后回去vs2008,f10往下走

4, you will see var x = context.Response.IsClientConnected; the x is false. (  the x must be false,or do it again )

4,走到var x = context.Response.IsClientConnected;的时候你发现x是false,如果x不是false说明你有什么地方没弄好,重来。

5, ok, continue to press f10 to step over context.Response.End();

5,然后继续f10执行完所有代码

6. ok , now all the code have been run. but you can see the current thread of asp.net development server is still alive by  NetLimiter 2 Pro or someother monitor program.

6,这个时候你发现 NetLimiter 2 Pro 监视的刚才的asp.net的线程没有被销毁

 

 

------------------

 

 

------------------

 

Ok , now delete the line "var x = context.Response.IsClientConnected;",let's go test2.

 好了,现在你把var x = context.Response.IsClientConnected这句话注释掉,再测试一遍,就正常了!


Code Snippet 2

class HelloWorldHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.Clear();

             //在这个断点触发的时候关上浏览器噢!You must close your browser at this breakpoint,
            context.Response.OutputStream.Write(new byte[]{1}, 0, 1);
            context.Response.Flush();
            //var x = context.Response.IsClientConnected;
            //When The x is false then step over next, you will see the thread in server do not destroy.
            context.Response.End();
        }
        public bool IsReusable
        {
            get
            {
                return true;
            }
        }
    } 

 


Ok , follow me ,let's go test2.

 下面开始测试2

 

 

1,First, press f5 to Debug. then the chrome window show, vs2008 break at first breakpoint,

1,f5 ,第一个断点到了,关掉浏览器

2,Close the chrome window!

3.back to vs2008, press f10 to step over until the next breakpoint

 3,回到vs 执行完所有代码

4, ok, continue to press f10 to step over context.Response.End();
5. ok , now all the code have been run. you can see the current thread of asp.net development server is destroyed , by  NetLimiter 2 Pro or someother monitor program.

5,你看到那个线程已经被自动销毁了。

 

---------------

 

 

 

----------------

我靠,是不是很邪门。 

Oh, It's strange!!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值