C# Difference between Beginaccept and Acceptasync

Asked

Viewed 188 times

5

  • It’s interesting because I read in the documentation that Async is an improvement over Begin.

  • Reply at Stackoverflow: http://stackoverflow.com/questions/24174423/c-sharp-socket-performance-with-net-4-5-async-vs-async-vs-begin

2 answers

1


None. One was made to meet an asynchronous programming "standard" and the other.

Behold: http://msdn.microsoft.com/en-us/library/jj152938(v=vs.110). aspx

The first "Begin" is to meet the APM (Asyncronous Programming Model) and the second (Blahblahblahasync) to meet the TAP (Task-based asyncronous Pattern). Tasks is newer and simpler to use.

On time, on my blog: http://ericlemes.com you find examples of server socket with both scenarios and some explanations on the gains obtained with asynchronous I/O in general.

0

In terms of performance, both are equal, the connection is always made using the class "Socket".

But in the example of Beginxxx, it is a simpler solution, using the basic form of the use of Async.

In the case of Xxxasync is an event-based example, this example is more complete because in this example it already expects up to 100 simultaneous connections as can be seen in this line:

listenSocket.Listen(100);

For description of what you need, you could use any of these solutions, however the Xxxasync is already closer and prepared for what you want, note that it is already an example of a server, just implement the desired actions.

Now, depending on what you’re going to do, and who you’re going to consume, you can eliminate several network layer concerns using WCF or even Webapi. But there will depend on the requirements of the project.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.