i have a method that creates a Process calling a console app.
double myProcess()
{
double results;
Process process = new Process();
process.EnableRaisingEvents = true;
process.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived);
process.StartInfo.FileName = filename;
process.StartInfo.Arguments = argument;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
return results;
}
static void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
string stringResults = (string)e.Data;
.
.
do some work on stringResults...
.
.
results = stringResults;
}
my problem is,how do i send data from process_OutputDataReceived back to myProcess? I cannot use singleton as there are possibilities that this process will be executed in multiple thread.
You don’t need a separate method for the
OutputDataReceivedhandler; you can use an anonymous method to set theresultsvariable directly:(Also, should
resultsbestringordouble?)Edit: A couple of alternatives for when you need to do more work in the handler: