1

Topic: Asynchronous at return of the data

All greetings! It is necessary to organize return to the client (browser) potentially great volume of the data,  on the fly (for example it there can be data in csv a format). The data is formed on the fly and is admissible is IEnumerable <string> at which search they and is formed. How it is better to make it correctly? By default, if to write Response. Write - that all data will go to the buffer and at their big amount we or we fly in OutOfMemoryException or  too much storage -  . If in asp.net to disconnect  an output at  in Response the data will be sent at once to a network and small slices? Whether has sense to organize the buffering (that at achievement of any data volume - they were sent to the client)? And how it is possible to do asynchronously? As generation and sending of the data can occupy a lot of time the flow processing , the most part of time will wait a network. . Who solved the similar task, or knows as it is possible, share knowledge...

2

Re: Asynchronous at return of the data

Hello, MadHuman, you wrote: MH> All greetings! MH> it is necessary to organize return to the client (browser) potentially great volume of the data,  on the fly (for example it there can be data in csv a format). MH> The data is formed on the fly and is admissible is IEnumerable <string> at which search they and is formed. MH> as it is better to make it correctly? MH> by default if to write Response. Write - that all data will go to the buffer and at their big amount we or we fly in OutOfMemoryException or  too much storage -  . MH> if in asp.net to disconnect  an output at  in Response the data will be sent at once to a network and small slices? Whether has sense to organize the buffering (that at achievement of any data volume - they were sent to the client)? MH> And how it is possible to do asynchronously? As generation and sending of the data can occupy a lot of time the flow processing , the most part of time will wait a network... MH> Who solved the similar task, or knows as it is possible, share knowledge... Read from a file. MemoryStream here it is absolutely not necessary.

3

Re: Asynchronous at return of the data

Hello, MadHuman, you wrote: MH> All greetings! MH> it is necessary to organize return to the client (browser) potentially great volume of the data,  on the fly (for example it there can be data in csv a format). MH> The data is formed on the fly and is admissible is IEnumerable <string> at which search they and is formed. MH> as it is better to make it correctly? MH> by default if to write Response. Write - that all data will go to the buffer and at their big amount we or we fly in OutOfMemoryException or  too much storage -  . MH> if in asp.net to disconnect  an output at  in Response the data will be sent at once to a network and small slices? Whether has sense to organize the buffering (that at achievement of any data volume - they were sent to the client)? MH> And how it is possible to do asynchronously? As generation and sending of the data can occupy a lot of time the flow processing , the most part of time will wait a network... MH> Who solved the similar task, or knows as it is possible, share knowledge... It is possible to create the class Stream which will be necessarily  the data "on the fly" and to push it in class FileResult.

4

Re: Asynchronous at return of the data

Hello, Sharov, you wrote: S> Read from a file. MemoryStream here it is absolutely not necessary.  there is no file. The data is on the fly formed.

5

Re: Asynchronous at return of the data

Hello, MadHuman, you wrote: S>> Read from a file. MemoryStream here it is absolutely not necessary. MH>  there is no file. The data is on the fly formed. Well so try to write to a file, especially if there can be many data, and then from a file drive to a network.

6

Re: Asynchronous at return of the data

Hello, Sharov, you wrote: S> Hello, MadHuman, you wrote: S>>> Read from a file. MemoryStream here it is absolutely not necessary. MH>>  there is no file. The data is on the fly formed. S> Well so try to write to a file, especially if there can be many data, and then from a file drive to a network.  then while all does not register a file to drive it does not turn out, there will be also a time delay big (while all will not be generated) and the file size can appear considerable.

7

Re: Asynchronous at return of the data

Hello, MadHuman, you wrote: S>> Well so try to write to a file, especially if there can be many data, and then from a file drive to a network. MH>  then while all does not register a file to drive it does not turn out, there will be also a time delay big (while all will not be generated) and the file size can appear considerable. What for all? Wrote down 1 in a file, beeped about cooking given to the sender, he sent 1 and will wait . A signal. Somehow so.

8

Re: Asynchronous at return of the data

PushStreamContent: [HttpGet] public HttpResponseMessage Export (int id) {var response = Request. CreateResponse (); response. Content = new PushStreamContent (async (outputStream, httpContent, transportContext) => {try {for (int page = 0; page <10; page ++) {string data = await GetData (id, page); var buffer = Encoding. UTF8.GetBytes (data); await outputStream. WriteAsync (buffer, 0, buffer. Length);}} catch (HttpException ex) {return;} finally {outputStream. Close ();}}, new MediaTypeHeaderValue ("application/octet-stream")); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue ("attachment") {FileName = "myfile.csv"}; return response;}