C# 3.0 in a nutshell says asynchronous methods and asynchronous delegates looks similar but the behavior is very different.
Here is what the book says about both.
Asynchronous methods
- Rarely or never blocks any thread.
- Begin method may not immediately return to the caller.
- An agreed protocol with no C# language support.
Asynchronous delegates
- May block for any length of time
- BeginInvoke return immediately to the caller.
- Built-in compiler support.
The book also says, The purpose of asynchronous methods is to allow many tasks to run on few threads; the purpose of asynchronous delegates is to execute a task in parallel with the caller.
When I looked into the BeginRead() method in System.IO.Stream class through reflector, it is using a delegate and calling BeginInvoke on that. So an asynchronous method is using an asynchronous delegate internally.
- In such case, how can one say their behaviors are different? Since it uses delegates internally, how a comparison like the above is possible?
- Do you think working with a delegate's BeginXXX method is the way to execute a function in parallel to the caller?
- What is the proper way to implement asynchronous methods by maintaining all the advantages like making good use of CPU?
Any thoughts?