I am programming a server-client socket software. On client side, when I click on the close window at the right upper side [X] Formclosing is initiated. I want to send to the server some information about disconnecting socket. My problem is that the client is in receiving state and I need to stop receiving state by calling socket.endreceive. I can't do that in Formclosing cause It need IASyncResult object that is not accessible.
Try closing the socket in the Formclosing method. This will cause socket.endreceive to throw an ObjectDisposedException exception.
Handle this exception in a try catch block.
Thank you for the answer. I know what endreceive does. What I want to do is currently using endreceive to stop reading state and sending a message to the server side. But on FormClosing, I don't see how I can call endreceive without IaSync object.