My application is a asp.net 3.5 running on iis 6 (windows 2003)
This application is serving 1000’s of users daily (100-500 users online).
I want to send an email newsletter to customers weekly.
Around 200,000 emails every time.
This is the code I’m using:
ThreadPool.QueueUserWorkItem(new WaitCallback(AsyncProcessMailerQueue), null);
private static void AsyncProcessMailerQueue(object data)
{
for (int i=0;i<users.count ; i++)
{
MailMessage message = new MailMessage();
.......
SmtpClient smtpClient = new SmtpClient();
smtpClient.Send(message);
}
}
When testing this locally (on my dev machine) I see the application is working a lot slower.
- Is there a better way to write this code?
- Should I use ThreadPool.QueueUserWorkItem or create a new thread using Thread t = new Thread(new ThreadStart(DoWork)); ?
- Will it be better to create a totally separate application for the purpose of sending the newsletters. will that help if ill run this application on the same machine?
I’ve seen other posts here talking about ThreadPool vs Thread but its seem no one is sure which is better.
In order of preference:
Thread t = new Thread(new ThreadStart(DoWork));