私は知って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;
}
}
問題は、クライアントが実際に受信したバイト数が my よりも非常に小さいことbytesSent
です。クライアントが切断されたとき、私のプログラムは大きな遅れで状況を見つけたようです (そして増加し続けbytesSent
ます)。
クライアントがいつ切断されたか (リアルタイム) を確認するための信頼できる方法はありますか?