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.
I've seen other posts here talking about ThreadPool vs Thread but its seem no one is sure which is better.
ASP.NET Core apps should be designed to process many requests simultaneously. Asynchronous APIs allow a small pool of threads to handle thousands of concurrent requests by not waiting on blocking calls. Rather than waiting on a long-running synchronous task to complete, the thread can work on another request.
Optimize Data Access Here are some techniques that you can use to increase app performance. Reduce the number of HTTP calls i.e. the number of network round trips. Instead of making multiple calls to the server, try fetching the data in one or two calls. Set a cache for unchanged data.
By default, TPL types like Task and Task<TResult> use thread pool threads to run tasks. You can also use the thread pool by calling ThreadPool.
In order of preference:
Thread t = new Thread(new ThreadStart(DoWork));
Moving out of asp.net would be a good choice. This could be a simple command line app you run from a command prompt. Why do you need a service or it to be hosted as a URL?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With