private void OnProgressChanged(object sender, EventArgsSendedMail e) { int count = e.CountFiles; int suc = e.SucMails; int fail = e.FailMails; UI.Progress(count, suc, fail, false); }
public void FindCSV() { try { if (Settings.FolderPath != "") { int FailMail = 0; int SucMail = 0; int СountFiles = 0; Log.Create(); var files = Directory.EnumerateFiles(Settings.FolderPath, "*.csv"); СountFiles = files.Count(); if (files.Count() == 0) { Log.Write(" *.csv files NOT FOUND in " + Settings.FolderPath); } else { EventArgsSendedMail eventArgs = new EventArgsSendedMail(СountFiles, 0, 0); foreach (var file in files) { Task.Delay(500).Wait(); if (StopButtonPressed) { Log.Write("User cancelled process!"); StopButtonPressed = false; break; } Log.Write("read " + Path.GetFileName(file)); if (ReadMailAdress(file)) { if (SendMessage(file)) { SucMail++; } else { FailMail++; } } else { FailMail++; } eventArgs.FailMails = FailMail; eventArgs.SucMails = SucMail; EventHandler <EventArgsSendedMail> eh2; lock (this) { eh2 = MailSendedEvent; } if (eh2 != null) { eh2(this, eventArgs); } } } Log.Write(SucMail + " letters have been sent successful"); Log.Write(FailMail + " letters have NOT been sent"); EventHandler <EventArgs> eh3; lock (this) { eh3 = SendingComplitEvent; } if (eh3 != null) { eh3(this, EventArgs.Empty); } if (Log.isCreate) { MessageBox.Show("Finish! Log with name \"" + Log.Name + ".txt\" has been created"); } } } catch (Exception ex) { EventHandler <EventArgs> eh3; lock (this) { eh3 = SendingComplitEvent; } if (eh3 != null) { eh3(this, new EventArgsSendedMail()); } Log.Write("The process failed. " + ex.Message); } }