This project is read-only.

Reconnecting to an IMAP host using the same object

Jul 19, 2011 at 12:25 AM
Edited Jul 19, 2011 at 12:26 AM

Hello everybody.


I wanted to create an application that is able to reconnect to an IMAP server automatically after it has been disconnected (probably accidentically).

In short something like that:

Imap4Client client = new Imap4Client();
client.Connect("Host", 143);
client.Login("username", "password");

// do something.... (accidentically disconnect)


// do something

client.Connect("Host", 143); client.Login("username", "password");

And here is the problem, after calling "client.Disconnect()" the TCP Socket gets disposed and is not available anymore.
Therefore I get an "object disposed" exception when I try to call "client.Connect()" again after I disconnected.

The only way to solve that is to create a new Imap4Client object. But this is not suitable for me, since I derivated my class from the Imap4Client class it is not
possible for me to use "new" to create a new object. The derivated class should be able to reconnect on its own, by probably creating a new Socket object internally.

Thank you for you answers and ideas.