Threads are typically created when you want your program to do more that one
thing at once.
In the following example I am using thread to send email as it can
using System.Threading;
private void SendEmail()
{
Thread objT1 = new Thread(new ThreadStart(EmailThread));
objT1.Start();
}
private void EmailThread()
{
MailMessage objEmail = new MailMessage();
objEmail.From = new MailAddress("myNamea@MyCompany.com", "Display Name Here");
objEmail.To.Add("To@MyCompany.com");
objEmail.Subject = "put test subject here";
objEmail.IsBodyHtml = true;
objEmail.Body = "Email body here";
SmtpClient objEmailSender = new SmtpClient("MYMailServerName");
//Send email
objEmailSender.Send(objEmail);
}
thing at once.
In the following example I am using thread to send email as it can
using System.Threading;
private void SendEmail()
{
Thread objT1 = new Thread(new ThreadStart(EmailThread));
objT1.Start();
}
private void EmailThread()
{
MailMessage objEmail = new MailMessage();
objEmail.From = new MailAddress("myNamea@MyCompany.com", "Display Name Here");
objEmail.To.Add("To@MyCompany.com");
objEmail.Subject = "put test subject here";
objEmail.IsBodyHtml = true;
objEmail.Body = "Email body here";
SmtpClient objEmailSender = new SmtpClient("MYMailServerName");
//Send email
objEmailSender.Send(objEmail);
}
No comments:
Post a Comment