Solved

Schedule function to run within asp.net web application

Posted on 2010-08-13
4
634 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

840 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