kusanagi
kusanagi

Reputation: 14624

asp.net mvc long operation

i need create an email list sending to many emails. what is best solution in mvc to call long time operation? better with example

Upvotes: 0

Views: 596

Answers (4)

Ian Mercer
Ian Mercer

Reputation: 39297

Likely you will need to do the following:-

  1. Create a Queue where you can put jobs to run
  2. Create an service that processes this queue
  3. Maybe report progress from the service back to the web site application
  4. Maybe report progress back to the user of the web application either on page refresh or more dynamically using Ajax

Some options for each of these components:-

1) Options for the job queue include an in memory queue Queue<>, a queue stored in a database, an MSMQ, a remote queue like Amazon's simple message queue. Which you chose will depend on how fault-tolerant you want the solution to be, whether you want to restart after a failure, and whether you need to distribute the work to multiple servers.

2) Options for the service include a thread within your web application or an NT Service. Again this will depend on your needs for fault-tolerance and restartability.

3) How you report progress back will depend on what kind of queue you used. For MSMQ you might have 'correlated' messages going back the other way. For a database queue you might mark the progress in the database. Or you might be calling a web service on the web application to report progress.

4) If you want a dynamic progress bar (or such like) to be shown to the user as the job progresses you can implement an Ajax service that passes the progress information from server to browser.

For sending email messages I would recommend using a database as your queue because you will likely want to be tracking them over a long period of time and marking undeliverable emails, emails that have been read, and such like in your database.

Upvotes: 1

37Stars
37Stars

Reputation: 2489

You don't want to run long processes like this on your web server. You want a "backoffice" application to handle sending emails and responses. Write another application that runs on a different computer. Have it read the information necessary from the database and send the emails. If you're sending emails you'll also need to handle the responses. This backoffice application should handle both.

Upvotes: 2

uvita
uvita

Reputation: 4124

I would suggest that you save the messages you want to send in a DB for example, along with the recipients. Then, you can use a scheduler (like Quartz.NEt) that checks every one minute (for example) if there are emails to be sent and in case there are, it sends up to 10 mails every time.

Upvotes: -1

Santiago Cepas
Santiago Cepas

Reputation: 4094

If you can employ ASP.NET MVC2, I'd use the new Asynchronous Controller

Upvotes: -1

Related Questions