Click or drag to resize
MimeKit

ImapClientIdleAsync Method

Asynchronously toggle the ImapClient into the IDLE state.

Namespace: MailKit.Net.Imap
Assembly: MailKit (in MailKit.dll) Version: 4.3.0
Syntax
C#
public Task IdleAsync(
	CancellationToken doneToken,
	CancellationToken cancellationToken = default
)

Parameters

doneToken  CancellationToken
The cancellation token used to return to the non-idle state.
cancellationToken  CancellationToken  (Optional)
The cancellation token.

Return Value

Task
An asynchronous task context.

Implements

IImapClientIdleAsync(CancellationToken, CancellationToken)
Exceptions
ExceptionCondition
ArgumentExceptiondoneToken must be cancellable (i.e. None cannot be used).
ObjectDisposedException The ImapClient has been disposed.
ServiceNotConnectedException The ImapClient is not connected.
ServiceNotAuthenticatedException The ImapClient is not authenticated.
InvalidOperationException A ImapFolder has not been opened.
NotSupportedException The IMAP server does not support the IDLE extension.
OperationCanceledException The operation was canceled via the cancellation token.
IOException An I/O error occurred.
ImapCommandException The server replied to the IDLE command with a NO or BAD response.
ImapProtocolException The server responded with an unexpected token.
Remarks

When a client enters the IDLE state, the IMAP server will send events to the client as they occur on the selected folder. These events may include notifications of new messages arriving, expunge notifications, flag changes, etc.

Due to the nature of the IDLE command, a folder must be selected before a client can enter into the IDLE state. This can be done by opening a folder using Open(FolderAccess, CancellationToken) or any of the other variants.

While the IDLE command is running, no other commands may be issued until the doneToken is cancelled.

Note  Note
It is especially important to cancel the doneToken before cancelling the cancellationToken when using SSL or TLS due to the fact that SslStream cannot be polled.
See Also