开发者

Simulating a cron job with a Task in Application Start

I'm trying to find a very easy easy way to start a simple cron job for my Web Application. What I was thinking about is starting a Task in the Application_Start event. This task will have a while loop and do some action every hour or so like a normal cron job would do.

Is this a good idea or w开发者_开发技巧ill this give some trouble?

Some of the problems I could think of are the following:

  • The Task suddenly stops working or hangs. Maybe make some fail over mechanism that would check if the task is still running and if not restart it.

  • Memory leaking if the Task totally goes wrong and I have to restart

    the whole application.

  • No control in changing the Task on the fly but this shouldn't be a

    problem for the thing I want to do but for others it might be.

Does someone have any suggestions or experiences with trying this?


Although Darin says that doing cron jobs in a web application is a bad idea (and I agree with him in some way), it may be not so bad, when used wisely and for short running jobs.
Using same Quartz.NET in web application may be quite nice, I'm using in one of my projects like this http://bugsquash.blogspot.com/2010/06/embeddable-quartznet-web-consoles.html for small jobs and it is running nice - it's easy to monitor (easier than monitoring remote windows process), may be used on shared hosting.


Doing cron jobs in a web application is a bad idea. IIS could recycle the application at any time and your job will stop. I would recommend you performing this in a separate windows service. You could take a look at Quartz.NET. Another possibility is a console application which does the job and which is scheduled within the Windows Scheduler.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜