Search code examples
c#asp.net-mvcmultithreadingthreadpoolmass-emails

Sending mass emails in the background - Create Thread or use ThreadPool?


I have an application in which an action triggers a number of emails to be sent out. The number of emails is variable and can be anywhere from 10 to 1,000 per action.

I don't want the application to hang while the emails are being sent (thus annoying the user) and would like to send them in the background.

I haven't used Threads in the past so that's why I need your help. Would you create Threads manually or is this a good case to use a ThreadPool? I want this task to be low priority and use the least amount of resources possible because I don't mind even if the email is 1 hour late.

Appreciate your help
Marko


Solution

  • Here goes another suggestion... If you`re using a DB, create a task (i.e. create a table that represents a task to be done) related with the messages that need to be sent and use Quartz.NET or similar (you may create a Windows Service too) that looks for incomplete tasks and executes them (marking them as done in case they are executed successfully).