I wanna ask you if is semantically correct that a gui WRITE on a socket? it could be a problem? There is the risk of block in the GUI ??
Thanks in advance
I wanna ask you if is semantically correct that a gui WRITE on a socket? it could be a problem? There is the risk of block in the GUI ??
Thanks in advance
It depends on how you've configured the socket. A non-blocking socket will not, of course, block your GUI thread. But IMHO they are considerably harder to write code around, due to the requirement to handle the non-fatal failure to send when you try to.
IMHO a much better model is to take advantage of one of the asynchronous paradigms sockets offer. Unfortunately, the System.Net.Sockets.Socket class hasn't been updated to fit with the new async/await features in C#. But it still has two very usable asynchronous models to choose from (either the original "Begin/EndXXX" model, or the 'XXXAsync" model, which in spite of its name doesn't work directly with async/await).
If you are willing to go to a slightly higher-level API with TcpListener, TcpClient and streams, then you can use async/await and this may provide you with an easier way to write the code. I found this earlier SO discussion in which someone's posted a short sample showing how that could be done: Using .Net 4.5 Async Feature for Socket Programming