When looking for an elegant way to asynchronously receive a stream of datagrams from a UDP socket, I came across this question: How to use asynchronous Receive for UdpClient in a loop?
The advantages of the first answer I understand, as they use the familiar BeginReceive
/EndReceive
methods. This solution is nice in that there are no threads hanging around being blocked.
The second answer, however gives two different Task-ish solutions, one using ReceiveAsync
and the other using the synchronous Receive
method. I'm wondering, in this case, what the advantage is. As I understand it, even in the ReceiveAsync
case, there's still a (threadpool?) thread waiting around for things to happen.
Is there an advantage in using Async methods in this case? If not, is there a way to implement this type of pattern using Async methods without the overhead of a thread, task, or other blocking object?