Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Schedule function to run within asp.net web application

Posted on 2010-08-13
4
Medium Priority
?
650 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 5

Accepted Solution

by:
chinawal earned 1500 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

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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.
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.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

609 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