Tuesday, 15 July 2014

c# - ASP.NET Threading: should I use the pool for DB and Emails actions? -


I'm looking for the best way to use threads that consider scalability and performance.

In my site, I have two scenarios which require threading:

  1. UI triggers: For example, the user clicks on a button, the server Read the data from DB and send some emails. Those actions take time and I do not want the user's request to be delayed. This scenario is very often.

  2. Background service: When the app starts, the thread is triggered every 10 minutes, reads from DB and sends emails.

I found solution:

Use a thread pool - the beginning invoke: I use it for both scenarios today. It works fine, but it uses the same thread that serve pages, so I think that I can run into scalability issues, can it be a problem?

No use of B pool - Thread Start: I know that if a new thread starts, then using a thread pool takes more resources. Can this approach work better for my scenarios? What is the best way to reuse the opened thread?

c. Custom Thread Pool: Because my scenarios are often the best way to start a new thread pool?

Thank you.

I will put it in a different service individually Write your UI action Make in the database, and do a different service, either choose the database or respond to the trigger, and sends the email at that time.

By separating it into a separate service, you do not have to worry about appdomain recycling etc. - and if you want you can keep it on a completely different server. I think this will give you a more flexible solution.


No comments:

Post a Comment