Async / waits with task.run vs task.run and continues in .NET 4.0

I installed the async package in .net 4.0. this gives me the ability to use async / wait keywords in my applications.

as I understand it so far, I can use wrap my task.run code in async / await and have the same result as using task.run with a continuation.

It's true? or are there deeper differences?

+8
c # async-await
source share
2 answers

It depends on what you do with ContinueWith . But yes, often you can use await to achieve the same effects that you previously achieved using ContinueWith . What you cannot do is such things as “continue this code only on failure” - for this you simply use the usual exception handling. As AlexH says, there will be further differences regarding the overall behavior of your async method, but in most cases I would say that this is desirable. Basically, asynchronous code is leaking, so async methods tend to call more asynchronous methods, etc.

I suggest you read what async / await (there are tons of resources out there - I would recommend the "Consuming page" Task-based asynchronous template "on the MSDN page as a starting point.

+11
source share

There will be a difference if you include the async keyword in your function prototypes; exceptions will be thrown at the caller level. Without the async keyword, you must check the status of TaskContinuationOptions.OnlyOnFaulted to get an exception.

+4
source share

All Articles