Is there a way to run a process every day in a .Net web application without writing a windows service or SQL server jobs

We require that in a ASP.Net application, a .Net process should be invoked every day at a specified time automatically. This process needs to interact with the database (SQL Server 2005) and generate billing on a daily basis. We are using a shared hosting hence we are not able to create a windows service or create SQL Server jobs. How can this be achieved without user intervention?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You could try the technique described here, used at StackOverflow itself (or at least it was used here at one point). In a nutshell:

  1. At startup, add an item to the HttpRuntime.Cache with a fixed
    expiration.
  2. When cache item expires, do your work, such as WebRequest or what have
    you.
  3. Re-add the item to the cache with a fixed expiration.

To get it to run at a specific time instead of an interval, you could lower the interval and simply modify your working method to check the time itself.


As the comments in the original article linked above note, this isn’t a perfect solution, and no one should prefer it over a proper scheduling technique if one is available. See When Does Asp.Net Remove Expired Cache Items? for some additional qualifications.

Method 2

Yes, use Windows Scheduler. Depending on how it’s configured you might need to be logged in for the scheduler to run.

Method 3

You could always schedule a task to run a webservice..

http://weblogs.asp.net/jgalloway/archive/2005/10/24/428303.aspx

The scheduler would run a VBS file with the following..

Set oServerXML = CreateObject("Msxml2.ServerXMLHTTP")
oServerXML.Open "GET","http://my.hostedservice.com/myService.asmx/myService?aParam=Value
oServerXML.setRequestHeader "Content-Type","application/x-www-form-urlencoded" 
oServerXML.Send
Set oServerXML = nothing

Method 4

Can’t be done, unfortunately.

IIS only responds to requests, and SQL Server only wakes up for jobs.

The closest you’ll be able to do is to put your routine in an ASPX page, not linked from the site and not with an obvious name, and trigger it by a request from some other machine out on the Internet.

The other machine could be a Windows, Linux, Mac, whatever you have available, and all of those platforms have ways of scheduling events (service, cron, etc.) that can make the request to trigger the update on the server.

Method 5

There are ways to run “services” in .Net by using cache expiration to trigger the task.

More at CodeProject

Method 6

You can use a Scheduled Task, but this might not work in a shared hosting environment either.

You could setup a webservice or page on your website to kickoff the process, then have a scheduled task on a desktop machine hit that page/service once daily to start the process. Hacky, but it might work.

Method 7

Being .NET ignorant, I would imagine there’s some kind of .NET based scheduler framework available for this (much like Quartz for Java).

Or you could simply fire off a long running thread that spends the bulk of its time sleeping, wake up every minute, check the time, check it’s list of “things to do”, fire off the ones that need to be done. Level of sophistication being as far as you want to take it, but the primary goal of keeping the primary scheduling thread “alive”, “at all costs”.

Method 8

What i can think about now are:

  • Create a dll which contain the
    schedule logic you want, and make
    sure that this dll schedule function
    will not stop and will loop for ever,
    then you will need a page on that
    server this page will fire this dll
    functions. “you will need to call
    this page at least once to start the
    scheduler”.
  • Create an application “holds schedule logic” on another machine, may be your Home PC, and make your pc application call the functions on the server through webservices or pages


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x