What's the different between an async delegate and async method?
Someone told me they were different in C#, but I thought they were the same thing.
Delegates first. When you declare one, the compiler automatically generates three methods for the delegate type:
The Invoke() method calls the delegate target synchronously, just like a plain call. The BeginInvoke() method is the asynchronous call, the target method runs on a thread-pool thread. The EndInvoke() call is required after the method completes to release resources allocated for the call and to re-raise any exception that might have aborted the call.
The .NET framework contains many classes that have a BeginXxxx() method. The MSDN Library refers to them as asynchronous operations, not asynchronous methods. They start an operation that completes asynchronously.
Starting with .NET 4.5 and supported by C# version 5, the asynchronous operations whose name end in Async and return a Task can be called in an await expression. When used in a method that has the async modifier. This greatly simplifies dealing with asynchronous operations, important in WinRT where many common operations are asynchronous.
For the differences, as well as some further discussion, see Asynchronous methods and asynchronous delegates right here on SO.
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