Friday, July 1, 2011

Threading in C#

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);

}

No comments:

Post a Comment

Open default email app in .NET MAUI

Sample Code:  if (Email.Default.IsComposeSupported) {     string subject = "Hello!";     string body = "Excellent!";    ...