I have a C# Console application that is executed using the windows server 2008 task scheduler, however when an exception occurs inside the application I still get "Task Completed" in the event log. I would like to trigger a task failed when an exception occurs.
1 Answer
You should make your console application return an int different from 0:
class Program {
static int Main(string[] args) {
try {
do_stuff();
return 0;
} catch (MyException exc) {
return 1;
}
}
}
3 Comments
user1362696
tried it but I still get "Task Completed", but the result code is shown in the event log.
Paolo Tedesco
Sorry, I didn't read carefully enough... I think that you get "task failed" only if your scheduled task does not find the program or something like that. Otherwise, the task is completed, but at least like this you get an error recorded somewhere. Sorry, I cannot test that right now.
Antonio Bakula
this is a only way, you can see that error code in Last Run Result or as ResultCode property of Action Completed event log entry