Solved

Schedule function to run within asp.net web application

Posted on 2010-08-13
4
630 Views
Last Modified: 2012-05-10
I am currently building a new web application that is a front end to a SQL database.  The application will allow the user to search and display items in the database.   It will also allow an admin to run a function, updateDB(), at the click of a button to update the database.  The update function will read an RSS Feed and put items from the feed into the database.  This all works fine however there is a request to have the update function automatically run nightly as well.   I am familiar with using Windows Scheduled Task to schedule an exe to run but is there a way to schedule a function in a web app to run?
Thanks.
0
Comment
Question by:Jaggster
4 Comments
 
LVL 5

Accepted Solution

by:
chinawal earned 500 total points
ID: 33431885
How about writing C# Windows Service?
If I were you, I would code C# Windows Service with Timer. It's easy and you may find ready-made code if you google it.

You can either set Timer frequency to wake up every 5 minutes and  'IF' condition to know if the current time is within 11:55 a.m. to 12:00 a.m.
(Once it executes, you can change Timer frequency to 24 hours.) . There are multiple ways you can put achieve that logic.
 
You should be able to call web app functions from Windows Service.  
0
 
LVL 5

Expert Comment

by:JayFromPep
ID: 33432473
Not really.  The ideal way would be to write an exe or service that can perform that action and schedule it or set it up to run via the service control panel.
0
 
LVL 18

Expert Comment

by:Gary Davis
ID: 33432720
The way I do this in asp.net is to insert an object (it doesn't matter what it is) in to the cache with an expire time of the time you want to run the task. When it expires, the code executes. It is asynchronous so there is no Request or Session object.
You have to check that the expiration is due to the expiration and not just because it was "pushed" out of cache. At the end of your processing, reschedule another expiration for the next time to run.
The code block shows the setup done at global.asa application start time and also called at the end of the RemovedCallback delegate.
Gary Davis
Webguild.com

var cacheExpireTime = (DateTime)cacheExpireTimeObject;



string cacheValue = String.Format("Inserted {0} to fire at {1}", DateTime.Now, cacheExpireTime);



var onRemove = new CacheItemRemovedCallback(RemovedCallback);



HttpRuntime.Cache.Insert(cacheName, cacheValue, null, cacheExpireTime, TimeSpan.Zero, CacheItemPriority.High, onRemove);



cacheDependency.Dispose();

Open in new window

0
 

Author Closing Comment

by:Jaggster
ID: 33458475
Although this project is push out a bit for me now I am going to attempt to use the windows service.  I hopefully will be able to find a way to call that service from the web application itself.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ASP.net VB.net Email  a webpage 3 24
Chat Room 1 25
Handle null when using linq in this line 1 20
Re-position the objects 7 47
Introduction (All good things must come to an end (http://en.wikipedia.org/wiki/All_Good_Things...)) The original MySQL API (http://php.net/manual/en/book.mysql.php) has gone away, deprecated by PHP in Version 5.5, and removed from PHP in all curre…
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now