How do I make HttpResponse.Flush () async?

How do I implement an asynchronous call to the HttpResponse.Flush () method using .net 4.0 and VS2013?

I tried delegating:

var caller = new AsyncFlush(context.Response.Flush);
var result1 = caller.BeginInvoke(null, null);
caller.EndInvoke(result1);

      

then execute the task:

Task.Factory.StartNew(() => context.Response.Flush()).Start();

      

and finally the stream:

new Thread(new ThreadStart(() => context.Response.Flush()).Start();

      

But every case seems to freeze my internet explorer when flushing large files (1GB +). Any idea?

Sincerely.

+3


source to share


2 answers


Your approach for creating the wrapper is asynchronous. But here are a few things you should know.

Response.Flush () makes the full buffer send to the client. Therefore, try not to send 1 click + data on the client at once. This can affect the client's handling of the huge buffer and can cause it to hang.



Instead of sending a huge buffer once to the client, try sending the stream in chunks and using a flash for each chunk so that the client doesn't hang while processing your request.

See this KB for writing a huge file in chunks in response with Response.Flush multiple times.

0


source


Whether your flush answer or not, it doesn't matter. It also doesn't matter what block size you use when writing the response object. The client and server communicate over TCP, which does not store or transfer block sizes. The client is never affected by how the server wrote. The client cannot even tell the difference if he wants to. This is a server implementation detail.

The reason your browser freezes is unknown, but that is not how you clear the data. Browsers load files of arbitrary size without problems.



Note that all three of the code samples you provided are either slightly harmful, pointless, or don't work at all. You need to throw it away. Look elsewhere to find the cause of the freeze.

+3


source







All Articles