在项目过程中遇到需要发送邮件的情况,反应特别慢,用户体验很不好,所以用了多线程
纯Asp.net项目以及mvc项目测试通过
1、无参数
Thread Thread1 = new Thread(new ThreadStart(Received));
Thread Thread2 = new Thread(new ThreadStart(SendMail));
Thread1.Start();
Thread2.Start();
Thread1.Join();
Thread.Sleep(1000);
Received和SendMail无参数的方法
2、带参数
System.Threading.Thread Thread1 = new System.Threading.Thread(() =>
{
Fun_CampaignInsert(campmaterial, campaign);
});
System.Threading.Thread Thread2 = new System.Threading.Thread(() =>
{
sendMail(campmaterial, campaign);
});
Thread1.Start();
Thread2.Start();
Thread1.Join();
System.Threading.Thread.Sleep(1000);
Fun_CampaignInsert和sendMail是带参数的方法