Is there a way to use the Task-based Asynchronous Pattern (TAP) in .NET 4.0 without the await
and async
keywords? (I ask because we are stuck in C# 4.0.)
Also, is there an example of using TAP with WCF with .NET 4.0?
Is there a way to use Task-based Asynchronous Pattern (TAP) in .NET 4.0 without the keyword await or async? I ask because we are stuck in C#4)
One notable and handy hack is to use yield
and IEnumerable<Task>
. E.g., from Stephen Toub's "Processing Sequences of Asynchronous Operations with Tasks":
IEnumerable<Task> DoExample(string input)
{
var aResult = DoAAsync(input);
yield return aResult;
var bResult = DoBAsync(aResult.Result);
yield return bResult;
var cResult = DoCAsync(bResult.Result);
yield return cResult;
…
}
…
Task t = Iterate(DoExample(“42”));
This way, you can have a pseudo-synchronous linear code flow similar to async/await
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With