I am at the moment messing around with clients and servers in C# winforms and I'm trying to implement it all asynchronously. However, I'm beginning to wonder, should I use asynchronous code for everything?
Here's a list of what I'm doing asynchronously at the moment:
TcpClient.BeginConnect with TcpClient.EndConnect
NetworkStream.BeginRead with NetworkStream.EndRead
TcpListener.BeginAcceptTcpClient with TcpListener.EndAcceptTcpClient
Listening thread on server for client connections
Listening thread on client for incoming data from server
Listening Task on server for incoming data from each client
New Task created every time an event such as ConnectionLost is raised (so the respective form can update). Think Delegate.BeginInvoke.
Everything is set up asynchrously and it works well, but I'm beginning to wonder if all of these should be asynchronous. I mean, it all sounds nice and people claim it to be efficient due to IO completion ports not blocking or something, but is it really?
I can understand having a single thread for listening on both the client and server, and for reading it makes sense as well. But every time an event is raised (which may be quite often!), should its invocation really be asynchronous? It seems like I am using Tasks for everything that can be made asynchronous and I'm not sure whether or not that is best practice.