开发适用于Windows计划任务 [英] Developing a scheduled task for Windows

查看:450
本文介绍了开发适用于Windows计划任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要开发使用C#.NET一个必须每天运行一次的应用程序。它只能运行最多一分钟了,所以开发一个Windows服务是矫枉过正和计划任务是合适的方式。

I have to develop an application using C#.net that has to be run once a day. It only runs for at most one minute, so developing a Windows service is overkill and a scheduled task is the appropriate way.

不过,我对应用程序如何传达其结果几个问题:

However, I have a few questions about how the application can communicate its results:

  • 如何指示的任务调度该任务已经失败了?通过程序的退出code是吗?
  • 如何记录输出信息?是控制台输出自动捕获或做我必须明确地写入事件查看器?

推荐答案

在回答您的问题 -

In answer to your questions -

  1. 如果任务失败,因为它抛出一个未经检查的异常,你会看到,在Sheduled任务观众,将有一个最后结果,其值类似于 0xe0434f4d 。另外,如果您返回退出code将也将在计划任务查看器的上次结果列中显示。

  1. If a task fails because it threw an unchecked exception you'll see that in the Sheduled Task viewer, there will be a 'Last Result' with a value something like 0xe0434f4d. Alternatively if you return an exit code that will be also be shown in the Last Result column of the Scheduled Task viewer.

写入控制台如 Console.WriteLine(嗒嗒); 将不会出现在任何地方。你需要写入到事件日志或日志文件。

Writing to the console e.g. Console.WriteLine("blah"); won't show up anywhere. You'd need to write to the event log or to a log file.

这篇关于开发适用于Windows计划任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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