This project is read-only.

PushStreamContent and async lambdas

Topics: ASP.NET Web API
Feb 27, 2013 at 2:32 PM
Edited Feb 27, 2013 at 2:33 PM
Hi, folks -

PushStreamContent only takes Actions as constructor parameters, so async lambdas are interpreted as async void methods. This causes problems with exception handling and can also cause race conditions (

Would you like me to contribute a fix? It would be rather simple and would not affect any other types. The constructor would be overloaded with Func types, and the "completion" logic changed so that the stream must be disposed and the method run to completion. This is slightly different than how PushStreamContent handles async lambdas today, but after this fix it would treat async lambdas the same as sync lambdas. I'll also supply unit tests for regression.

Feb 28, 2013 at 6:05 AM
Having an async lambda overload would be great! FWIW, the example on SO doesn't actually require the PushStreamContent -- it can just pass the HttpContents around. I added a sample "ASP.NET Web API sample showing how to relay requests and responses asynchronously and without buffering" ( to illustrate this.