public void Idle (CancellationToken doneToken, CancellationToken cancellationToken = default (CancellationToken))
{
if (!doneToken.CanBeCanceled)
throw new ArgumentException ("The doneToken must be cancellable.", nameof (doneToken));
CheckDisposed ();
CheckConnected ();
CheckAuthenticated ();
if ((engine.Capabilities & ImapCapabilities.Idle) == 0)
throw new NotSupportedException ("The IMAP server does not support the IDLE extension.");
if (engine.State != ImapEngineState.Selected)
throw new InvalidOperationException ("An ImapFolder has not been opened.");
using (var context = new ImapIdleContext (engine, doneToken, cancellationToken)) {
var ic = engine.QueueCommand (cancellationToken, null, "IDLE\r\n");
ic.UserData = context;
ic.ContinuationHandler = (imap, cmd, text) => {
imap.State = ImapEngineState.Idle;
doneToken.Register (IdleComplete, context);
};
engine.Wait (ic);
ProcessResponseCodes (ic);
if (ic.Response != ImapCommandResponse.Ok)
throw ImapCommandException.Create ("IDLE", ic);
}
}