简体   繁体   English

Windows Scheduler-将任务状态切换为失败

[英]Windows Scheduler - switch Task status to Fail

I'm currently developping a C# program that will be run every hour via the Windows Task Scheduler. 我目前正在开发一个C#程序,该程序将通过Windows Task Scheduler每小时运行一次。 I would like to know if there is a way for my program to return a specific value that will mark the task as failed if something went wrong. 我想知道我的程序是否有办法返回特定值,如果出现问题,该值会将任务标记为失败。
I mean, do the Windows Task Scheduler expect certain type of return code when running a program? 我的意思是,Windows Task Scheduler在运行程序时是否期望某些类型的返回码?
Something Like: 就像是:
0 <=> Everything is OK 0 <=>一切正常
Any other Value <=> ERROR 任何其他值<=>错误

I found this but I think that it's more when you use the Task Scheduler API, and that allows you to get the task status. 我发现了这一点,但我认为使用Task Scheduler API时会发现更多,并且可以获取任务状态。

Thank you for the Help! 感谢您的帮助!

I would just log the results to the Event Viewer. 我只是将结果记录到事件查看器中。 Then you can monitor it there with details. 然后,您可以在那里进行详细监视。

How to write to an event log by using Visual C# 如何使用Visual C#写入事件日志

You can return an int value in your main method, that value will be displayed in the "Last run Result" in the Task Scheduler. 您可以在主方法中返回一个int值,该值将显示在任务计划程序的“上次运行结果”中。

static int Main() {
    return -1;
}

That will show 0xffffffff in the task scheduler 这将在任务计划程序中显示0xffffffff

You can also use the System logs to provide more details about the error 您还可以使用系统日志来提供有关错误的更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM