开发者

Running a queue-based background process on an externally hosted website

I have an ASP.NET MVC web application which is hosted by an external provider, on IIS 7.

I wish to run a process every 15 minutes or so, which checks a backlog of emails that need to be sent, and actually sends them.

It seems that the normal way to do this is with Microsoft Message Queue, b开发者_Go百科ut since this is a hosted environment which I can't directly control, I won't be able to install or configure MSMQ.

So far I've decided to do it by appending rows to a table in my SQL Server database (same hosting).

So how should I implement the bit where I check the backlog and send the emails?

Should it be some kind of separate thread in my main web application, which restarts itself every 15 minutes?

Another option I considered was just opening an HTTP-POST interface which, when called with an appropriate admin password, runs an iteration of the email sender.

I could then create a small console app on my local PC which calls the interface every 15 minutes.

The first option is simpler, but the second might be more robust.

Any ideas?


I would recommend you taking a look at Quartz.NET. Also an important thing you should be aware is that the web server could unload the ASP.NET application from memory if it is not used meaning that all threads that have been spawned would simply die. That's one of the reasons why such tasks shouldn't be performed in ASP.NET applications but rather offloaded in Windows Services.


Jeff Atwood did a post on how he originally achieved the badge system on Stack Overflow using an expiring cache to reset the process periodically.

https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/

I have done something similar to this in the past sending emails out every day. The service was non essential, and it didn't matter if the emails missed a day or two, as they would go out eventually anyway, but the system worked quite well. It's all asp.net so works fine in the hosting environments I use, without access to service on the server or creating a local trigger from your desktop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜