如何运行.NET程序,自动,每隔一小时 [英] How to run a .NET program, automatically, every hour

查看:193
本文介绍了如何运行.NET程序,自动,每隔一小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的XML数据我通过Web服务访问。我需要读取数据,并复制它在本地。下面code正常工作。我现在需要至少两次或者运行code,一天三次wihout人工干预。我怎么做?谢谢!

 使用系统;
System.Collections中使用;
使用System.Data这;
使用的System.Xml;


 类MainClass {
公共静态无效的主要(){
XmlDocument的文档=新的XmlDocument();
// 读
doc.Load(新System.IO.StringReader(GetContracts()));

// 写
XmlTextWriter的TW =新的XmlTextWriter(testOut.xml,NULL);
tw.Formatting = Formatting.Indented;
tw.Indentation = 4;
doc.Save(TW);
tw.Close();
}
}
 

解决方案

使用任务计划程序。有一个GUI和命令行界面来设置任务。
如果使用图形用户界面,发现它在开始....控制面板....管理工具......在Vista上。你可以找出如何每小时轻松地运行您想想,pretty的。

如果您使用命令行,检查文档: http://msdn.microsoft.com/en-us/library/bb736357(VS.85).aspx

  SchTasks.exe会/创建/ TN我的任务
            / TRC:\路径\到\中\ APP.EXE ARG1 ARG2
            / SC每日/ RI HOURLY
            / ST 12:00:00 / RU用户名/密码RP
 

(以上应该是所有对一在线)

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

解决方案

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)

这篇关于如何运行.NET程序,自动,每隔一小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆