开发者

How should I run a background service for creating export files for a web site in the Windows world?

开发者 https://www.devze.com 2022-12-16 14:35 出处:网络
I\'ve created a shiny new ASP.Net MVC site and I have offloaded the \'s开发者_开发知识库ave as\' type of functionality to a helper program that can be run in the background on the server so that the w

I've created a shiny new ASP.Net MVC site and I have offloaded the 's开发者_开发知识库ave as' type of functionality to a helper program that can be run in the background on the server so that the website doesn't need to take all that load.

I created it so that it's easy to run from the command line and right now I have it running from a windows scheduler. The problem is that that has a granularity of 1 minute, which means that some unlucky users of the website will click on the link and get a 59s wait + the time to actually process the report.

I'm also slightly worried about the start up cost of my program. I'm assuming that it would be cheaper to keep the program running constantly. I am worried about the program dying and not being respawned though. With the windows scheduler option at least I don't have to worry about my program bailing so much.

How have you dealt with that?


I'd create a Windows Service and have that running instead of an exe via windows scheduler. You can then set it to auto-start. Then you can just have a timer within the service to poll for work every x seconds.

Another alternative is to use something like MSMQ. Your front end would just insert a message into the queue to represent the work to do, then have a .NET service listening to the queue (you can get it to process messages immediately they appear in the queue, or check the queue manually yourself every x seconds).

Either way, I think a Windows Service is the way to go.

0

精彩评论

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