I have list of ReferenceIDs (string) in a dataset. These ReferenceIDs can have values like this ("CQ1258891","CQ1258892","CQ1258893"....""CQ1258993"). I have a logic in my code to send a mail for each ReferenceIDs.
As of now I am looping through the every ReferenceID synchronously. Due to which, it take more time to send every mail. I have been using .NET 3.0, so I dont have option to use TPL in .NET 4.0.
I have been looking for a multithreaded machanism to send the mails for every ReferenceID asynchronously. As of now, I have tried the following code but it's not working as expected.
foreach (DataRow row in qrefSet.Tables[0].Rows)
{
string refId = Convert.ToString(row["ReferenceID"]);
if (!string.IsNullOrEmpty(refId))
{
Thread thread = new Thread(() => apeDBAdapter.SendEmail(personId, refId, parentReferenceID, customerName, queueId));
thread.Start();
}
}
Please share the effective machanism to achieve multithreaded foreach loop for my implementation.
Thanks, Sriram