如何找到一个asp.net客户端立即断开连接
我知道
Response.IsClientConnected
但在我的情景中它有很大的滞后。码:
// sample code for sending a dynamic file in chuncks
long bytesSent = 0;
while (continueSending)
{
if (!AskReceiverToContinue())
break;
if (!Response.IsClientConnected)
break;
// Your suggestion goes here... :)
try
{
Response.OutputStream.Write(buffer, 0, buffer.Length);
bytesSent += buffer.Length;
}
Catch
{ // To my experience, this is more reliable than Response.IsClientConnected
continueSending = false;
}
}
问题是客户端实际接收的字节数量远远小于我的bytesSent
。似乎当客户端断开连接时,我的程序发现了一个很大的滞后情况(并继续增加bytesSent
),这是因为ASP.NET告诉我情况(客户端断开连接)迟到了。
是否有任何可靠的方法可以找出客户端何时断开连接(实时)?
没有找到相关结果
已邀请:
1 个回复
皇小福另届