线程化:如何在数据库中插入数据并使用线程同时发送邮件 [英] Threading : how to insert datas in db and sending mail simulteously using threading
本文介绍了线程化:如何在数据库中插入数据并使用线程同时发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将数据插入数据库并使用线程一次发送邮件。
受保护 void btnSave_Click( object sender ,EventArgs e)
{
DB.SetConnectionParameter( (local) , Sams, sa, 12345);
尝试
{
对象 [,] 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 (例外情况){}
}
下一封电子邮件发送代码我也有
解决方案
protected void btnSave_Click(object sender,EventArgs e)
{
ThreadStart InsertionThread = new ThreadStart(insert);
线程t1 =新线程(InsertionThread);
t1.Priority = ThreadPriority.Highest;
t1.Start();
// insertion();
ThreadStart MailThread = new ThreadStart(Mail);
线程t3 =新线程(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>有人想和你联系< br> +< b>名称:< / b> + txtName.Text +< br />< b>电子邮件:< / 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 =新对象[,] {{& 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){}
} < /预>
I want to insert datas in to db and sending mail at a time using threading.
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
解决方案
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[,] { { "@Name", txtName.Text }, { "@Address", txtAddress.Text }, { "@EmailId", txtEmailId.Text } }; DB.ExecuteNonQuery_SP("InsertThreading", obj); } catch (Exception ex) { } }</pre>
这篇关于线程化:如何在数据库中插入数据并使用线程同时发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文