private void WorkerThreadFunc() { if (settings != null && true) { dbHelper helper = new dbHelper(); string smtpEmailAddress = settings["SMTPUserName"]; string smtpPassword = settings["SMTPPassword"]; // string fromEmail = settings["FromEmail"]; // string fromDisplayName = settings["FromDisplayName"]; string smtpClientHost = settings["SMTPHostName"]; int smtoClientPort = int.Parse(settings["SMTPHostPort"]); bool enableSsl = bool.Parse(settings["EnableSSL"]); bool useDefaultCredentials = bool.Parse(settings["UseDefaultCredentials"]); int emailForBulk = 50, reTryTime = 5; int.TryParse(settings["EmailForBulk"], out emailForBulk); int.TryParse(settings["ReTryTime"], out reTryTime); var databundle = helper.GetmailBulk(DateTime.Now, emailForBulk); var notsendbundle = helper.GetFailedBulk(reTryTime); if (databundle != null) { databundle.AddRange(notsendbundle); } else { databundle = notsendbundle; } if (databundle != null) { helper.SetSettingFromKey("LastRunTime", DateTime.Now.ToString()); Parallel.ForEach(databundle, item => { string newGuid = Guid.NewGuid().ToString(); var mail = new mailDetails() { guid = newGuid, mail = item }; collection.Add(mail); sendEmail(mail, smtpEmailAddress, smtpPassword, smtpClientHost, smtoClientPort, enableSsl, useDefaultCredentials); }); } } current_thread_count--; if (!emailerTimer.Enabled) { emailerTimer.Start(); } }