I'm using the System.Diagnostics.Process class to execute a command line program.
I am using the OutputDataReceived method to redirect the output to my own method.
pr.OutputDataReceived += new DataReceivedEventHandler(OnDataReceived);
pr.ErrorDataReceived += new DataReceivedEventHandler(OnDataReceived);
However, I have multiple Threads running multiple instances of this cmd program. What I want to do is to be able to identify which process instance the output data came from - ideally, a string containing a name. (Each process has it's own progress bar on a GUI. I create another event to pass the output to the GUI, thus, I need to know which process the data came from to update their progress bar).
I started to experiment with:
public override delegate void DataReceivedEventHandler(object sender, DataReceivedEventArgs e, string processName);
Then I realised that I would have to override the OutputDataReceived method inside the Process class. Which in turn would mean I have to create a custom class that inherits System.Diagnostics.Process, and have a method that accepts a string argument so the OutputDataReceived event can pass the process instance name (string) to my overridden DataReceivedEventHandler.
The purpose of the question is to get some opinions on how to proceed. Does what I propose seem the right way to accomplish what I want? Or, is there a better way to do it?