1

I have a C# console application, which is triggered on Windows Task Scheduler periodically, but I need to get the "Correlation ID" of process started and pass to my app by argument, like the code below:

class Program
{
    static void Main(string[] args)
    {
        if (args.Length > 0)
            Console.WriteLine($"This is the Correlation ID start process: {args[0]}");
    }
}

See here more details about the information that I need ScreenShot

I found the "Add argument" option in Task Scheduler Action Window, but I don't know what to put there to retrieve "Correlation ID" process.

See here the "Add argument" option above mentioned ScreenShot

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • I assume by this https://stackoverflow.com/questions/10215238/how-can-i-find-the-instanceid-correlation-id-of-the-scheduled-task-that-started that if you can't know it from inside the .exe, you can't pass it either. – LucasMetal Aug 05 '19 at 14:05
  • Thanks @LucasMetal, but I really need the Correlation ID for my context. – André P. Bertoletti Aug 07 '19 at 23:03

1 Answers1

0

You should have a look at the answer to this question. From the currently executing process you can get the parent tasks PID (process identifier) and use that as a correlation identifier. If you really need access to the parents command line arguments then this answer should help you there.

Bigtoe
  • 3,372
  • 1
  • 31
  • 47