I'm trying to use the IMAP IDLE feature to detect new mail. When a new mail is detected, the IDLE should stop and I will download the new mail.
However, when I call EndCheckForUpdates from the Notification event handler, it's just hanging. See example code below:
The class have these members:
IAsyncResult async = null;
The client is properly connected to the server, and the inbox is selected. Then I do:
client.Notification += new ImapNotificationEventHandler(client_Notification);
async = client.BeginCheckForUpdates(15*60000, CallBack, null);
This method is being called when a new mail arrives:
void client_Notification(object sender, ImapNotificationEventArgs e)
client.Abort(); // Tried both with and without this one
if (async != null)
The problem is that the EndCheckForUpdates method call doesn't finish. How do I solve this? I want to cancel the IDLE as soon as I get a mail notification.