Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make HttpResponse.Flush() async?

How to implement an asynchrone call to the HttpResponse.Flush() method using .net 4.0 & VS2013 ?

I tried delegate:

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

then task:

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

and finally thread:

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

But each case seem freeze my internet explorer when flushing larges files (1GB+). Any idea?

Regards.

like image 623
Giglagla Avatar asked Jun 18 '26 19:06

Giglagla


1 Answers

Whether your flush the response or not does not matter. It also does not matter what chunk size you use when writing to the response object. Client and server communicate over the TCP protocol which does not preserve or communicate chunk sizes in any way. The client is never impacted by the way the server wrote. The client can't even tell the difference if it wanted to. It's an implementation detail of the server.

The reason why your browser "freezes" is unknown but it is not the way you flush data. Browsers have no trouble downloading arbitrarily sized files.

Note, that all three of the code samples you posted are either slightly harmful and pointless or do not work at all. You need to throw this away. Look elsewhere for finding the reason for the freeze.

like image 151
usr Avatar answered Jun 21 '26 08:06

usr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!