locked
How to Return ExitCode from C# App running in Azure Batch RRS feed

  • Question

  • I have C# app running in Azure Batch.

    How can i fail and return a Exitcode so that Task fails in Azure Data Factory from C# code ?

    Thursday, January 25, 2018 11:22 PM

Answers

All replies

  • I found it myself:

    Environment.Exit(<Any Non Zero Value to Indicate Failure>);

    Saturday, January 27, 2018 3:31 AM
  • Using Environment.Exit() is a very unceremonious way for your program to exit because it triggers an immediate process termination. No cleanup code will have a chance to operate - for example, any open network connections will be left open, dangling. Depending on what your task is doing, this might result in dropped transactions (that rollback), resource exhaustion, and so on.

    This stack overflow question/answer goes into more detail: 
    https://stackoverflow.com/questions/5253158/using-environment-exitcode-versus-returning-int-from-main?noredirect=1&lq=1

    If memory serves, an ADF task is just a console application - so your .NET project will include a Program.cs file with an entry point like this:

    static void Main(string[] args)
    {
        // ...
    }

    To set a particular exit code, change Main() to return an int thusly:

    static int Main(string[] args)
    {
        // ...
        return -1;
    }


    Saturday, January 27, 2018 8:32 PM