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

2019-07-18 15:18发布

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();
}
}

3条回答
SAY GOODBYE
2楼-- · 2019-07-18 15:40

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.

查看更多
放我归山
3楼-- · 2019-07-18 15:47

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)

查看更多
做个烂人
4楼-- · 2019-07-18 15:51

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/

查看更多
登录 后发表回答