I've got a web-based file download problem that I can't figure out.

OS: Windows XP Pro
IDE: Visual Studio.NET Enterprise
Language: C#, ASP.NET

What I need to be able to do is determine if the user completed the file
download - maybe their connection is really slow and they decide they don't
want to wait for the download so they click the cancel button. I've tried
breaking the file into data chunks and writing only a chunk at a time, then
checking to see if the client is still connected (Response.IsClientConnected)
but when I cancel the download before it's finished the page freezes and
kicks me out of the debugger and back to the browser. The application event
log has an error that
says: "aspnet_wp.exe (PID: 2436) was recycled because it was suspected to
be in a deadlocked state. It did not send any responses for pending requests
in the last 180 seconds." I thought the latest service pack, .NET Framework
Service Pack 2, would fix my problem since it lists this problem in it's
bug fixes but it didn't make any difference after I installed the service
pack.

http://support.microsoft.com/default...b;en-us;321884
321792 FIX: ASP.NET Worker Process (Aspnet_wp.exe) Is Recycled Unexpectedly

I have been unsuccessful in my search for not only an answer but also in
my search for finding anyone else trying to make sure the entire file was
downloaded to the client computer. I can't find any useful information about
the file download dialog box events, although I'm not sure how much that
would really help. There must be a way to do this and I thought Response.IsClientConnected
was the answer.


Here is my relevant code:

HttpResponse myResponse = HttpContext.Current.Response;
FileInfo myFile = new System.IO.FileInfo(strFilePath[0]);
int intTotalFileDownLoaded = 0;

myResponse.Clear();
myResponse.BufferOutput = true;
myResponse.AddHeader("Content- Disposition", "attachment; filename=\""
+ strFilePath[1] + myFile.Extension + "\"");
myResponse.AddHeader("Content-Length", myFile.Length.ToString()); myResponse.ContentType
= "application/octet-stream"; myResponse.Flush();

int intByteSize = 1024 * 1000; //made this big so it wouldn't impact performance
much

int intOffset;
int intFileChunks = (int)Math.Ceiling((double)(myFile.Length/intByteSize));

for (int intCount = 0; intCount < intFileChunks + 1; intCount++) {
//want to use myResponse.IsClientConnected but it's
//freezing the system
if (myResponse.IsClientConnected)
{
intOffset = intCount * intByteSize;

//intByteSize is probably larger than the final chunk of
//data so figure how big that last chunk is so the end
//data size isn't past the end of the file
if ((intOffset + intByteSize) > (int)myFile.Length)
{
intByteSize = (int)(myFile.Length - intOffset);
}

myResponse.WriteFile(strFilePath[0], intOffset, intByteSize);
myResponse.Flush();
intTotalFileDownLoaded = intOffset + intByteSize;
}
else
{
strDownloadStatus = "Failed";
}

if (intTotalFileDownLoaded == myFile.Length)
{
strDownloadStatus = "Successful";
}
}