所以即时尝试推迟从我的程序发送电子邮件。 为了保持UI的交互性,我开始了一个新线程,并在线程中调用了email方法。有用。它发送电子邮件。但我不知道如何睡觉的线程。 我试着在实际的电子邮件方法中使用Thread.sleep(),但它似乎没有工作。睡觉一个新的线程c#
Thread oThread = new Thread(new ThreadStart(() => { sendEMailThroughOUTLOOK(recipientAddress, subjectLine, finalbody); }));
oThread.Start();
电子邮件方式..
public void sendEMailThroughOUTLOOK(string recipient, string subject, string body)
{
Thread.Sleep(60000);
try
{
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set HTMLBody.
//add the body of the email
oMsg.Body = body;
oMsg.Subject = subject;
// Add a recipient.
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient);
oRecip.Resolve();
// Send.
oMsg.Send();
// Clean up.
oRecip = null;
oRecips = null;
oMsg = null;
oApp = null;
}//end of try block
catch (Exception ex)
{
}//end of catch
//end of Email Method
}
也许这是一个愚蠢的问题,但为什么你想要线程睡觉? –
你有没有看过使用计时器? –
在调试器中逐步完成。我猜你可以自己找到这个问题。这是一项重要的学习技能。 – usr