If you want to write asynchronous code, then you should use async
/await
. I have an intro on my blog with a number of followup resources at the end.
When you start an asynchronous operation (e.g., Invoke
), then you get a task back. The Task
type is used for asynchronous operations without a return value, and Task<T>
is used for asynchronous operations with a return value. These task types can indicate to your code when the operation completes and whether it completed successfully or with error.
Although you can use Task.Wait
and Task<T>.Result
, I don't recommend them. For one, they wrap any exceptions in an AggregateException
, which make your error handling code more cumbersome. It's far easier to use await
, which does not do this wrapping. Similarly, you can register a callback using ContinueWith
, but I don't recommend it; you need to understand a lot about task schedulers and whatnot to use it correctly. It's far easier to use await
, which does the (most likely) correct thing by default.