Solved

Schedule function to run within asp.net web application

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Scheduled IIS .Net2 AppPools recycle and SQL connection Hangs 33 88
XAML: Layout 8 25
Export import database 4 41
ASP.NET Core index.html  LOCALHOST page cannot be found 2 22
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

919 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

14 Experts available now in Live!

Get 1:1 Help Now