Reputation:
I've done an small asynchronous
tcp server/client in C#...
... And I've been just thinking :
C# API implements select
and epoll
, a classic but easy way to do async. Why does Microsoft introduce the BeginConnect
/BeginSend
family, which -in my opinion- have a more complicated design (and adds lines of code too).
So, using the BeginXXX() "trend", I noticed that the System.Threading
import is required (for the events). Does it mean that threads are involved too ?
Upvotes: 3
Views: 293
Reputation: 171178
select and poll have two problems:
It is much nicer to be able to just specify callback that magically will be called on completion. This scales automatically and there is no central place to dispatch needed. Async IO in .NET is quite free of hassles. It just works (efficiently).
Async IO on Windows is threadless. While an IO is running not a single thread is busy serving it. All async IO in .NET uses truly async IO supported by the OS. This means either overlapped IO or completion ports.
Look into async/await which also can be used with sockets. They provide the easiest way to use async IO that I know of. That includes all languages and platforms. select and poll aren't even in the same league judged by ease of use.
Upvotes: 4