私のプログラムからの電子メールの送信を遅らせようとしています。UI をインタラクティブに保つために、新しいスレッドを開始し、スレッドで email メソッドを呼び出しました。できます。メールを送信します。ただし、スレッドをスリープさせる方法がわかりません。実際の電子メール メソッドで Thread.sleep() を使用してみましたが、うまくいかないようです。
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
}