Reputation: 38365
I write to Response.OutputStream, and make intermediate flush calls on Response.OutputStream.Flush(). However, the client doesn't show any data transferred until I call Response.Flush().
I'm using stream to stream approach to keep memory footprint low for large downloads, but it's not actually sending data to client, which means it's accumulating it in the response and consuming memory instead of flushing it to the client.
As a test, I did this and added a long wait, deployed it to IIS (just to be sure it wasn't some behavior of IIS Express):
largeFileStream.CopyTo(Response.OutputStream);
Response.OutputStream.Flush();
Thread.Sleep(10000);
Response.Flush();
The browser doesn't show any data transfer until after 10 seconds when Response.Flush is called.
I also tried a buffered loop with OutputStream.Flush calls after each loop, but same result.
Why doesn't Response.OutputStream.Flush()
trigger any data transfer to the client?
Upvotes: 2
Views: 613
Reputation: 12748
You have to set Response.BufferOutput = false before you begin writing to OutputStream if you want it to stream to client immediately.
I think one flush on the device while the other just flush from memory to the device.
Upvotes: 3