Async implementation of IValueConverter

You probably don’t want to call Task.Result, for a couple of reasons. Firstly, as I explain in detail on my blog, you can deadlock unless your async code is has been written using ConfigureAwait everywhere. Secondly, you probably don’t want to (synchronously) block your UI; it would be better to temporarily show a “loading…” or … Read more

How does await async work in C# [closed]

MSDN explains everything. I understand though that sometimes vanilla docs (particularly from MSDN) can be difficult to apply to your particular situation, so let’s go over your points. Question # 1: Is this assumption correct or the code below the await keyword is still executed? The code below the “await” keyword will only be executed … Read more

Is it possible to “await yield return DoSomethingAsync()”

What you are describing can be accomplished with the Task.WhenAll method. Notice how the code turns into a simple one-liner. What happens is that each individual url begins downloading and then WhenAll is used combine those operations into a single Task which can be awaited. Task<IEnumerable<string>> DownLoadAllUrls(string[] urls) { return Task.WhenAll(from url in urls select … Read more

How does Task become an int?

Does an implicit conversion occur between Task<> and int? Nope. This is just part of how async/await works. Any method declared as async has to have a return type of: void (avoid if possible) Task (no result beyond notification of completion/failure) Task<T> (for a logical result of type T in an async manner) The compiler … Read more

Why can’t I catch an exception from async code?

You have the “Just my code” Option turned on. With this on, it is considering the exception unhandled with respect to “just your code”–because other code is catching the exception and stuffing it inside of a Task, later to be rethrown at the await call and caught by your catch statement. Without being attached in … Read more

I want await to throw AggregateException, not just the first Exception

I disagree with the implication in your question title that await‘s behavior is undesired. It makes sense in the vast majority of scenarios. In a WhenAll situation, how often do you really need to know all of the error details, as opposed to just one? The main difficulty with AggregateException is the exception handling, i.e., … Read more