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

守給你的承諾、 提交于 2019-12-14 03:57:25

问题


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

回答1:


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.

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)




回答2:


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:


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/



来源:https://stackoverflow.com/questions/2421252/how-to-run-a-net-program-automatically-every-hour

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!