Tutorial :windows service versus asp.net Application_BeginRequest event with threads/timers



Question:

What are the advantages/disadvantages to running time based jobs using:

  1. windows services

  2. Application_BeginRequest to start seperate threads / timers.

One disadvantage of running the jobs in the context of a asp.net web appplication is during .net recycling things will have to be setup again, any others?


Solution:1

To my mind, there's no real benefit to doing time-based things in a web app. Go straight to a windows service. You know the process should be up and running all the time.

The ASP.NET site may simply unload, and will only operate again once someone starts browsing. The lifecycle is all wrong -- it's much 'choppier' than a service.

Lastly, services aren't very hard to create.


Solution:2

If you have administrative access to the server, I would either run a Windows Service or a scheduled SQL job depending on what you are trying to achieve.

It is nice to be able to stop/start and log these jobs independent of your web application. Also, if you have problems or errors in the job, it could adversely affect your website.

Finally, you are forcing the web application to go through code at every request to see if the timer has elapsed, which is an unnecessary overhead.

As I said to start with, the implementation depends on what the job is. If it is simply to update a number of database records, I'd use a scheduled job in SQL Server. If you need file I/O or access to external services, then a Windows Service might be more appropriate.

It is worth noting that you need to build in your own scheduling and thread safety into Windows Services. An alternative is to build a console application and use an application like FireDaemon for the scheduling.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »