简体   繁体   中英

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. 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?
Something Like:
0 <=> Everything is OK
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.

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#

You can return an int value in your main method, that value will be displayed in the "Last run Result" in the Task Scheduler.

static int Main() {
    return -1;
}

That will show 0xffffffff in the task scheduler

You can also use the System logs to provide more details about the error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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