Torna al Thread

public void invio() { if (textBox1.Text.Length == 0 && textBox2.Text.Length == 0) { MessageBox.Show("Please Fill The \"From\" and The \"To\" Field.", "Missing", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (textBox1.Text.Length == 0) { MessageBox.Show("Please Fill The \"From\" Field.", "Missing", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (textBox2.Text.Length == 0) { MessageBox.Show("Please Fill The \"To\" Field.", "Missing", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } progressBar1.Value = 0; progressBar1.Minimum = 0; progressBar1.Maximum = Convert.ToInt32(comboBox2.SelectedItem.ToString()); int nom = Convert.ToInt32(comboBox2.SelectedItem.ToString()); for (int i = 0; i <= nom; i++) { try { this.Title = "UFO Mail - Sending..."; Cursor = Cursors.Wait; MailMessage Msg = new MailMessage(); Msg.From = new MailAddress(textBox1.Text.ToString()); Msg.to.Add(new MailAddress(textBox2.Text.ToString())); Msg.Subject = textBox3.Text.ToString(); Msg.Body = richTextBox1.Document.ToString(); Msg.IsBodyHtml = true; SmtpClient Smtp = new SmtpClient(comboBox1.SelectedItem.ToString()); Smtp.DeliveryMethod = SmtpDeliveryMethod.Network; NetworkCredential Credential = new NetworkCredential(); Smtp.UseDefaultCredentials = false; Smtp.Credentials = Credential; Smtp.Send(Msg); progressBar1.Value = +1; if (progressBar1.Value == nom) { MessageBox.Show("message Sent!", "Sent", MessageBoxButton.OK, MessageBoxImage.Information); this.Title = "UFO Mail"; Cursor = Cursors.Arrow; progressBar1.Value = 0; } } catch { MessageBox.Show("Houston, We Have a Problem!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); this.Title = "UFO Mail"; Cursor = Cursors.Arrow; progressBar1.Value = 0; return; } } } private void button1_Click(object sender, RoutedEventArgs e) { Thread myThread = new Thread(new ThreadStart(invio)); myThread.Start(); }
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5