private static void Timer_Elapsed(object sender, ElapsedEventArgs e) { var processUIDs = _allUIds.GetRange(_batchStartIndex, _batchLength); Console.WriteLine("Timer Processing", processUIDs); Parallel.ForEach(processUIDs, async uid => { CustomClient client = null; if (MailConnectionManager.TryGetClient(out client)) { Console.WriteLine(client.Id); var proxy = new MailProxy("imap.gmail.com", EncryptionType.UNENCRYPTED, ref client); if (!client.Connected) { proxy.Login("ramankingdom", "letusc"); } proxy.SetWorkingEmailFolder("Inbox"); var header = await proxy.GetEmailHeaderAsync(uid); Console.WriteLine(ApplicationHelpers.ConvertBytesToString(header)); client.FreeClient(); } } ); }