MailKit.Net.Imap.ImapClient.IdleAsync C# (CSharp) Метод

IdleAsync() публичный Метод

Asynchronously toggle the ImapClient into the IDLE state.

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 MailKit.MailFolder.Open(FolderAccess,System.Threading.CancellationToken) or any of the other variants.

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

It is especially important to cancel the doneToken before cancelling the cancellationToken when using SSL or TLS due to the fact that System.Net.Security.SslStream cannot be polled.
/// must be cancellable (i.e. cannot be used). /// /// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// A has not been opened. /// /// The IMAP server does not support the IDLE extension. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server replied to the IDLE command with a NO or BAD response. /// /// The server responded with an unexpected token. ///
public IdleAsync ( CancellationToken doneToken, CancellationToken cancellationToken = default(CancellationToken) ) : System.Threading.Task
doneToken System.Threading.CancellationToken The cancellation token used to return to the non-idle state.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат System.Threading.Task
		public Task IdleAsync (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.");

			return Task.Factory.StartNew (() => {
				lock (SyncRoot) {
					Idle (doneToken, cancellationToken);
				}
			}, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default);
		}