public override void Run() { TraceLine("TaskStoreMailWorker started", "Information"); string hostname = ConfigurationManager.AppSettings["Hostname"]; int port = Int32.Parse(ConfigurationManager.AppSettings["Port"]); string username = ConfigurationManager.AppSettings["Username"]; string password = ConfigurationManager.AppSettings["Password"]; #if IDLE // idle support means we can use an event-based programming model to get informed when var mre = new System.Threading.ManualResetEvent(false); using (var imap = new ImapClient(hostname, username, password, ImapClient.AuthMethods.Login, port, true)) TraceLine("Connected", "Information"); imap.SelectMailbox("inbox"); // a new message comes in imap.NewMessage += Imap_NewMessage; while (!mre.WaitOne(5000)) //low for the sake of testing; typical timeout is 30 minutes imap.Noop(); }