Solved

Schedule function to run within asp.net web application

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

813 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

15 Experts available now in Live!

Get 1:1 Help Now