本文介绍了在DataReceivedEventHandler中获取Process.ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从DataReceivedEventHandler内部确定进程ID?
主代码启动多个进程,我需要确定哪个进程生成了DataReceivedEvent.
Hi,
Is it possible to determine the process id from within a DataReceivedEventHandler?
The main code launches multiple processes and I need to determine which process generated the DataReceivedEvent.
Process process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = Application.StartupPath + @"\RTMPdump\rtmpdump.exe";
process.StartInfo.Arguments = "-r \"" + StreamLoc + "\" -o \"" + fileName + ''"'';
if (process.Start() == true)
{
process.OutputDataReceived += new DataReceivedEventHandler(ProcessDataReceived);
process.ErrorDataReceived += new DataReceivedEventHandler(ProcessDataReceived);
process.Exited += new EventHandler(ProcessExited);
process.BeginOutputReadLine();
process.BeginErrorReadLine();
}
void ProcessDataReceived(object sendingProcess, DataReceivedEventArgs outLine)
{
if (InvokeRequired)
{
Invoke(new InvokedExecution(delegate()
{
if (!String.IsNullOrEmpty(outLine.Data))
{
// unfortunate this \/ \/ does not work...
textBox1.Text = outLine.ProcessID.ToString() + outLine.Data.ToString();
}
}));
}
else
{
if (!String.IsNullOrEmpty(outLine.Data))
{
//textBox1.Text = outLine.ProcessID.ToString() + outLine.Data.ToString();
}
}
}
有什么想法吗?
预先感谢.
Any ideas?
Thanx in advance.
推荐答案
Process proc = sendingProcess as Process;
string r = proc.Id.ToString();
还是谢谢,
Ultravox
Thanx anyway,
Ultravox
这篇关于在DataReceivedEventHandler中获取Process.ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!