netNewbi3
netNewbi3

Reputation: 279

How to run a .NET program, automatically, every hour

I have xml data I access through a web service. I need to read the data and copy it locally. The below code works fine. I need now to run this code at least twice or three times a day wihout manual intervention. How do I do that? Thanks!

using System;
using System.Collections;
using System.Data;
using System.Xml;


 class MainClass{
public static void Main(){
XmlDocument doc = new XmlDocument();
// read
doc.Load(new System.IO.StringReader(GetContracts()));

// write
XmlTextWriter tw = new XmlTextWriter( "testOut.xml", null );
tw.Formatting = Formatting.Indented;
tw.Indentation = 4;
doc.Save( tw );
tw.Close();
}
}

Upvotes: 2

Views: 4339

Answers (3)

Cheeso
Cheeso

Reputation: 192657

Use Task Scheduler. There's a GUI and a Command Line interface to set up tasks.
If you use the GUI, find it in Start....Control Panel....Administrative Tools... on Vista. You'll be able to figure out how to run your think hourly, pretty easily.

alt text

if you use the command line, check the doc: http://msdn.microsoft.com/en-us/library/bb736357(VS.85).aspx

schtasks.exe /create /tn "My Task" 
            /tr "C:\path\to\the\app.EXE arg1 arg2" 
            /sc DAILY /RI HOURLY  
            /st 12:00:00 /ru username /rp password

(The above should be all-on-one-line)

Upvotes: 2

Andy Trujillo
Andy Trujillo

Reputation: 26

Quartz is a good scheduler for java, of course you will either need to setup the jar to start with windows or install on an application server like Tomcat or Jetty.

http://www.quartz-scheduler.org/

Upvotes: -1

Mitchel Sellers
Mitchel Sellers

Reputation: 63136

It really depends on how you want the scheduling to be done. If it is only a few times a day, I would just schedule the application to be executed on a regular basis using the Task Scheduler within Windows.

Upvotes: 1

Related Questions