What’s actually difference between Asynchronous Programming Model and Event-based Asychronous Pattern?
Which approach to use and when?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The Asynchronous Programming Model (APM) is the model you see with
BeginMethod(...)andEndMethod(...)pairs.For example here is a
Socketusing the APM implementation:The Event-based Asynchronous Pattern (EAP) is the model you see with
MethodAsync(...)andCancelAsync(...)pairs. There’s usually aCompletedevent.BackgroundWorkeris a good example of this pattern.As of C# 4.5, both have been replaced by the
async/awaitpattern, which is using the Task Parallelism Library (TPL). You will see them marked withAsyncafter the method name and usually returning an awaitableTaskorTask<TResult>. If you are able to target .NET 4.5, you should definitely use this pattern over the APM or EAP design.For example, compressing a (potentially large) file asynchronously: