I've got about 40 lines of .NET code in a console application that read and RSS feed and store information in a database. I need this code to execute every night for as long as the RSS feed exists (indefinitely). Currently, I just launch the console app. from my home computer.
Because I can't trust myself to remember to do this every night, I somehow need to have this code hosted. I'd like to somehow have this app. or code (it could easily be put in an ASP.NET page codebehind and triggered to execute when the page loads) run automatically without me having to run the console app. manually.
Any ideas?
EDIT: I don't want to run this code from my computer; I can't guarantee my computer will not be hibernating or connected to the Internet every night.
EDIT: Right now I'm thinking spawn a background thread using BackgroundWorker in Application_Start of the global.asax, have it download the RSS feed once a day, and Thread.Sleep() the rest of the time.
Although controversial, Jeff Atwood blogged about how they accomplished this for SO using cache expiration. Check it out at https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/.
You could use a similar method and schedule the cache to expire at the time you want the process to kick off.
You could use the Windows built-in task scheduler to start the console application.
I would suggest just using the 'at' command instead of getting this small app hosted somewhere.
C:\>at /?
The AT command schedules commands and programs to run on a computer at
a specified time and date. The Schedule service must be running to use
the AT command.
Email your webhost. Some managed hosts will set up a scheduled task for you.
They will likely have different policies regarding how to call a scheduled task (i.e. some may require it to be an aspx page and not an EXE)
Have you looked at Quartz Scheduler for .NET?
Quoth the tagline: Quartz.NET is a full-featured, open source job scheduling system that can be used from smallest apps to large scale enterprise systems.
Related
I want to create one Task Scheduler using C# same as Windows Task Scheduler, to run my .bat (batch) file on particular time.
I found this useful link (http://www.codeproject.com/Articles/38553/TaskScheduler)
in this they schedule trigger, and i want to Schedule my .bat file I mean while i am trying to give my batch file path in tags textbox, its just fired trigger, not run my batch file so, i modify that code little bit, and now I am able to run my batch file also,
but, when i close my application triggering also stop, so, is there any way i can triggering or run my batch file even if i close my application, like window task scheduler???
kindly Help me .
Note: its desktop application using C#
You can programmatically schedule tasks in the Windows Task Scheduler by using this .NET wrapper or by calling the windows command line utility schtasks yourself.
It seems you need a windows service to execute your scheduled tasks. Also see Quartz.NET project, that can be used from smallest apps to large scale enterprise systems.
You can programmatically make a task schedule using Windows Task Scheduler
or you can make a background process or a more recommended approach, a thread so your program still runs in the background and still has a small footprint.
I have a ASP.NET website running on Server 2003 with SQL-Server as database.
I have two tasks that I want to automate on daily basis.
1) Update the Lucene search index file
2) Update the profile pic of all user from LDAP server
I have both codes in aspx pages but I want them to run daily at midnight or 4 am in the morning or something like that. I havent done any automation before so I am clueless. So
my question is...
What are my options?
Thank you :)
You've got some options:
There is this on Code Project Simulate a Windows Service using ASP.NET to run scheduled jobs
You can write your own Windows service.
You can go the commercial route and use a web based scheduler. Two popular ones are:
web.scheduler and web based cron
Another option is to create a Windows scheduled task. When the task fires off, you can have it hit a page that runs the logic you wish to perform. Here's a linked solution on SO: Recommended method for loading a URL via a scheduled task on Windows
If you're looking for automation within your asp.net web application, consider Quartz.net as a good free, open source solution. We've been using it to automate maintenance tasks and are quite happy with the results.
I am writing a backup process.
Step1: User selects 3 times (Tuesday 1am,3am,10am or Everyday 1am,3am,10am)
Step 2: The application should check the time settings and start the backup process automatically.
Is it possible to start the backup process if the application is not running?
if your client/user is using Windows operating system then you can use Windows Task Scheduler to do the job. To schedule the job programmatically see this post and this post
why don't you use Windows Schedule ?
Sure, just use the Windows Task Scheduler. Windows will take care of running your application.
IMO you can use Windows Scheduler, that is the best. and Also do care of TimeZones :P :P
here are the links which may help you.
Task Scheduler
I have a requirement where an application which is run by windows service to be executed on specific days in a week(Sunday through Saturday). These days should be stored in a config file and can be changed by user at any time.
Can you please point to right direction in achieving this. Please let me know if you need any clarification on this.
I'd suggest using Windows Task Scheduler instead of a service to launch the application. It is designed for this scenario.
If You are in Windows environment, then you can use Windows Task Scheduler.
The following is for Windows XP, but the instructions are almost the same for other versions of Windows
http://support.microsoft.com/kb/308569
Simple. Windows Operating System TASK SCHEDULER. Start your application at specific days. Finished.
How about registering them to the scheduled tasks?
It already has a great interface and any user can deal with them, let alone your costumer's IT depeartment.
You can also create a tool that registers the scheduled task to windows with parameters according to the XML file.
I agree with all the above.
Windows Task Scheduler would be the best and easiest solution.
You could even write a console application and set it to run at given times.
Here is a small guide to console applications for scheduled tasks:
http://www.15seconds.com/issue/080508.htm
As everyone has answered, Windows Scheduler is already part of Windows and will do this for you. However, if you need a programmatic answer to this, you can use the following C# code:
// Read in your configuration file
// and I am assuming you are reading in the file and storing the
// Days of the week you need it to run in a string array
foreach (string DayToRun in MyStringArray)
{
if (DateTime.Now.DayOfWeek.ToString().ToUpper().Equals(DayToRun.ToUpper())
{
// Today is the day we need to execute.
// Do execution here
System.Diagnostics.Process.Start("C:\\MyProgramToExecute.EXE");
break;
}
}
I've created a shiny new ASP.Net MVC site and I have offloaded the 'save as' type of functionality to a helper program that can be run in the background on the server so that the website doesn't need to take all that load.
I created it so that it's easy to run from the command line and right now I have it running from a windows scheduler. The problem is that that has a granularity of 1 minute, which means that some unlucky users of the website will click on the link and get a 59s wait + the time to actually process the report.
I'm also slightly worried about the start up cost of my program. I'm assuming that it would be cheaper to keep the program running constantly. I am worried about the program dying and not being respawned though. With the windows scheduler option at least I don't have to worry about my program bailing so much.
How have you dealt with that?
I'd create a Windows Service and have that running instead of an exe via windows scheduler. You can then set it to auto-start. Then you can just have a timer within the service to poll for work every x seconds.
Another alternative is to use something like MSMQ. Your front end would just insert a message into the queue to represent the work to do, then have a .NET service listening to the queue (you can get it to process messages immediately they appear in the queue, or check the queue manually yourself every x seconds).
Either way, I think a Windows Service is the way to go.