Martin
Martin

Reputation: 24308

PushStreamContent vs Task Action?

Can anyone help, I wish to return a asynchronous Stream from asp.net web api and it appears there is more than one way of doing or I don't understand the difference.

For example, you are able to do a PushStreamContent to a standard HttpResponseMessage or it appears you can implement Task and await etc.

What are the differences??

Should I be always returning a stream even for small amounts of data?

Is that is the case should i always be using Async Tasks?

Seems very confusing and I have googled the difference but i can't seem to find a specific answer.

Upvotes: 1

Views: 1450

Answers (1)

Alex S
Alex S

Reputation: 1221

Ultimately it depends what you are trying to do in your case, here is an example of PushStreamContent I found:

http://aspnet.codeplex.com/SourceControl/changeset/view/9cb7243bd9fe3b2df484bf2409af943f39533588#Samples/WebApi/PushContentControllerSample/PushContentController/Controllers/PushContentController.cs

Few observations about PushStreamContent that make it valuable in comparison to custom await implementation:

1) It monitors output stream and makes a callback when it is available. 2) It completes the response when output stream closes.

Let us know what you are trying to do, perhaps I can give a more specific answer.

Upvotes: 1

Related Questions