Possible Duplicate:
delaying the sending of email messages without using Thread.Sleep c#
so i am trying to start a new thread inside a for loop of my application. Im not familiar with threading at all so I need some info.
im sending emails through outlook using this method:
public void sendEMailThroughOUTLOOK(string recipient, string subject, string body)
{
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
}
and in a foreach loop i send an email each iteration.
However i need those emails delayed, but I dont want to sleep the UI thread.
I asked a few hours ago and got some answers but wasnt able to check my question frequently.
I tried some of their suggestions such as using this:
Thread oThread = new Thread(new ThreadStart((sendEMailThroughOUTLOOK(recipient, subjectLine, finalbody)));
But im getting an error. Its saying its expecting a method name…and i do have a method name in there. Is it because of the arguments of my method?
You can do this or also look into ParameterizedThreadStart: