1

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 1

2

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;
        }
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

tried it but I still get "Task Completed", but the result code is shown in the event log.
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.
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.