Hi, I am writing an terminal app that would allow you to connect to POP3
server and receive mail data in raw format. Now the POP3 server expects a
graceful disconnection by sending a "quit\r\n" command to it. The server then
replies you with a "+OK ... Goodbye" message.
Now I have a code as follows for the disconnect button:---
<pre>
private void btnDisconnect_Click(object sender, System.EventArgs e)
{
if (serverSock != null)
{
if (serverSock.Connected)
{
Send(serverSock, "quit\r\n");
sendDone.WaitOne();
serverSock.Shutdown(SocketShutdown.Both);
serverSock.Close();
serverSock = null;
}
}
}
</pre>
Now the problem arises when this code executes. By the time the "quit\r\n"
command is sent to the server and the server sends a response message, the
socket object is already null and an Object Already disposed exception
arises..
Is there anything I can do to make the system wait asynchronously before the
socket is closed ???