C# Console App Exit Code with Task Scheduler

4.1k Views Asked by At

I have a C# Console application that runs under Windows Task Scheduler.

Should the application fail for what ever reason, I use "Exit Codes" to propagate back to Task Scheduler.

However, no matter what I try, Task Schedule logs always report "Task Completed Successfully".

I have tried the two defined exit strategies.. being...

Environment.Exit(hasError ? -1 : 0);

and

static int Main(string[] args)
{
    ... code ...
   return (hasError ? -1 : 0);
}

Any suggestions what I may be doing wrong

Running app in Windows Server 2012 Standard

1

There are 1 best solutions below

0
On BEST ANSWER

Turns out its a Windows 2012 Server issue and requires the following hot-fix

https://support.microsoft.com/en-us/kb/3003689