public event ExtendedAsyncCompletedEventHandler<TResult> CheckForUpdatesCompleted
Shows how to handle Update event and use the CheckForUpdatesAsync asynchronous method to check for updates/notifications from the IMAP server (Task-based asynchronous approach).
using System; using System.ComponentModel; using ComponentPro; using ComponentPro.Net.Mail; ... public async void DoNoopAsync() { // Create a new instance of the Imap class. Imap client = new Imap(); // Connect to the server. await client.ConnectAsync("myserver"); // Or you can specify the IMAP port with // client.Connect("myserver", 143); // Login to the server. await client.AuthenticateAsync("user", "password"); // ... // Select the 'INBOX' mailbox. await client.SelectAsync("INBOX"); // Register an event handler. client.Update += client_Update; while (true) { // Check for updates in 10 seconds. await client.CheckForUpdatesAsync(10000); // Check your loop condition. // ... } // ... // Disconnect. client.Disconnect(); } void client_Update(object sender, ImapUpdateEventArgs e) { switch (e.Event) { case ImapUpdateEvent.MessageCount: Console.WriteLine("New message received."); // You can download the newly received message here. break; case ImapUpdateEvent.MessageRemoved: Console.WriteLine("One or more messages removed."); break; } }
Shows how to handle Update event and use the CheckForUpdatesAsync asynchronous method to check for updates/notifications from the IMAP server (Event-based asynchronous approach).
using System; using System.ComponentModel; using ComponentPro; using ComponentPro.Net.Mail; ... public void DoNoopAsync() { // Create a new instance of the Imap class. Imap client = new Imap(); // Connect to the server. client.Connect("myserver"); // Or you can specify the IMAP port with // client.Connect("myserver", 143); // Login to the server. client.Authenticate("user", "password"); // ... // Select the 'INBOX' mailbox. client.Select("INBOX"); // Register an event handler. client.CheckForUpdatesCompleted += client_CheckForUpdatesCompletedCompleted; client.Update += client_Update; // Check for updates in 10 seconds. client.CheckForUpdatesAsync(10000); // ... // Disconnect. client.Disconnect(); } void client_Update(object sender, ImapUpdateEventArgs e) { switch (e.Event) { case ImapUpdateEvent.MessageCount: Console.WriteLine("New message received."); // You can download the newly received message here. break; case ImapUpdateEvent.MessageRemoved: Console.WriteLine("One or more messages removed."); break; } } void client_CheckForUpdatesCompletedCompleted(object sender, ExtendedAsyncCompletedEventArgs<bool> e) { Imap client = (Imap)sender; if (e.Error != null) Console.WriteLine("Error: " + e.Error.ToString()); else { // Check for updates again. You might want to check some condition before going into the loop again. client.CheckForUpdatesAsync(10000); } }