KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a multi-threaded winforms application. One thread for the GUI, and one thread for background processing. In the background processing, I communicate with an external process via the Process class to send an receive data. I am confused about what thread the handler that I registered Process.OutputDataReceived is run on. According to MS documentation: "The OutputDataReceived event indicates that the associated Process has written to its redirected StandardOutput stream." But it isn't clear who is raising the event. See example code below: myProc= new Process(); myProc.StartInfo.UseShellExecute = false; myProc.StartInfo.RedirectStandardOutput = true; myProc.StartInfo.RedirectStandardError = true; myProc.StartInfo.RedirectStandardInput = true; myProc.StartInfo.FileName = "myapp.exe"; myProc.StartInfo.Arguments = arguments; myProc.StartInfo.CreateNoWindow = true; myProc.OutputDataReceived += new DataReceivedEventHandler(DataReceivedFromProc); myProc.ErrorDataReceived += new DataReceivedEventHandler(ErrorReceivedFromProc); myProc.Start(); myOutputStream = myProc.StandardInput; myProc.BeginOutputReadLine(); myProc.BeginErrorReadLine(); So in this case, what thread is DataReceivedFromProc run on? Does it make a difference if the above is executed on my GUI thread vs worker thread?
Tags (comma-separated)
Save Edits
Cancel