Crystalbyte.Equinox.Imap.ImapClient.StartIdle C# (CSharp) Method

StartIdle() public method

This method is blocking. The IDLE command may be used with any IMAP4 server implementation that returns "IDLE" as one of the supported capabilities to the CAPABILITY command. If the server does not advertise the IDLE capability, the client MUST NOT use the IDLE command and must poll for mailbox updates. http://tools.ietf.org/html/rfc2177
public StartIdle ( ) : void
return void
        public void StartIdle()
        {
            if (!ServerCapability.IsIdleSupported) {
                const string message = "Server does not support the idle command. Please check Capability.CanIdle before calling Idle.";
                throw new InvalidOperationException(message);
            }

            var command = new ImapCommand("IDLE");
            SendAndReceive(command);
            IsIdling = true;

            while (true) {
                // Need to set response timeout to 29 minutes, because the server will kick us after 30  if we do not re apply for IDLE.
                ResponseTimeout = TimeSpan.FromMinutes(29);
                var reader = new ImapResponseReader(this);
                try {
                    ReceiveIdleStatusUpdates(reader);
                }
                catch (TimeoutException) {
                    StopIdleAsync();
                }

                if (reader.IsCompleted) {
                    break;
                }
            }

            IsIdling = false;
        }

Usage Example

Ejemplo n.º 1
0
        public void ThreadStart()
        {
            _clientIdle = AccountController.CreateClientByAccount(AccountController.Account);
            Thread.Sleep(1000);

            _clientIdle.StatusUpdateReceived += OnStatusUpdateReceived;
            _clientIdle.Select("INBOX");
            _clientIdle.StartIdle();
        }