Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to insert datas in to db and sending mail at a time using threading.


C#
protected void btnSave_Click(object sender, EventArgs e)
   {
       DB.SetConnectionParameter("(local)", "Sams", "sa", "12345");
       try
       {
           object[,] obj=new object[,]{ { "@Name", txtName.Text }, { "@Address", txtAddress.Text }, { "@EmailId", txtEmailId.Text } };
           DB.ExecuteNonQuery_SP("InsertThreading", obj);

           DataSet ds = new DataSet();
           ds = DB.ExecuteQuery_SP("displayDetails");
           GridView1.DataSource = ds.Tables[0];
           GridView1.DataBind();
       }
       catch (Exception ex) { }
   }


next email sending code also i had
Posted
Updated 22-Jul-13 18:48pm
v5

1 solution

protected void btnSave_Click(object sender, EventArgs e)
    {
       
    

        ThreadStart InsertionThread = new ThreadStart(insertion);
        Thread t1 = new Thread(InsertionThread);
        t1.Priority = ThreadPriority.Highest;
        t1.Start();
        //insertion();

        ThreadStart MailThread = new ThreadStart(Mail);
        Thread t3 = new Thread(MailThread);
        t3.Start();
        //Mail();
        display();
        

        
    }

  public void Mail()
    {
        MailMessage mail = new MailMessage();
        mail.From = new MailAddress("mhdaktar1@gmail.com");
     
        mail.To.Add(txtEmailId.Text);
        mail.IsBodyHtml = true;
        mail.Subject = "test";
        //mail.Body = "<br><br>Someone want to contact you <br>" + "<b>Name:</b>" + txtName.Text+ " <br/> <b>Email :</b>" + txtEmailId.Text + ";
        mail.Body = "welcome";
        SmtpClient smtp = new SmtpClient("smtp.gmail.com",587);
        smtp.Credentials = new System.Net.NetworkCredential("mhdaktar1@gmail.com", "9995100143"); 
        smtp.EnableSsl = true;
         smtp.Send(mail); 
    }
       
       
        
<pre lang="cs">public void insertion()
  {
      try
      {
          object[,] obj = new object[,] { { &quot;@Name&quot;, txtName.Text }, { &quot;@Address&quot;, txtAddress.Text }, { &quot;@EmailId&quot;, txtEmailId.Text } };
          DB.ExecuteNonQuery_SP(&quot;InsertThreading&quot;, obj);
      }
      catch (Exception ex) { }

  }</pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900