ProcessStartInfo 和带有参数的事件/异步
ProcessStartInfo and event / async with parameter
我有一个 href 列表,我 运行 它在这个位置 (svn) 异步查找的命令。
在 ProcessOnErrorDataReceived 中,我必须将 s + outLine 添加到列表中。我不知道该怎么做。可以发送 s 到一个事件或者我需要同步调用一个方法。
Search(List<string> path) {
foreach(var s in path){
...
if (process.StartInfo.RedirectStandardOutput)
process.OutputDataReceived += ProcessOnErrorDataReceived;
}
}
private void ProcessOnErrorDataReceived(object sendingProcess,
DataReceivedEventArgs outLine)
{
Process p = sendingProcess as Process;
if (outLine.Data != null)
list.Add(outLine.Data); //Here +s
}
尝试这样的事情。
这里我们创建一个闭包并捕获 locS 值。因此,当事件发生时,我们可以将捕获的值传递给 ProcessOnErrorDataReceived
Search(List<string> path)
{
foreach(var s in path)
{
...
if (process.StartInfo.RedirectStandardOutput)
{
var locS = s;
process.OutputDataReceived += (sender,e) =>
ProcessOnErrorDataReceived(sender, e, locS);
}
}
}
private void ProcessOnErrorDataReceived(object sendingProcess,
DataReceivedEventArgs outLine, string s)
{
Process p = sendingProcess as Process;
if (outLine.Data != null)
list.Add(outLine.Data + s); //Here +s
}
我有一个 href 列表,我 运行 它在这个位置 (svn) 异步查找的命令。 在 ProcessOnErrorDataReceived 中,我必须将 s + outLine 添加到列表中。我不知道该怎么做。可以发送 s 到一个事件或者我需要同步调用一个方法。
Search(List<string> path) {
foreach(var s in path){
...
if (process.StartInfo.RedirectStandardOutput)
process.OutputDataReceived += ProcessOnErrorDataReceived;
}
}
private void ProcessOnErrorDataReceived(object sendingProcess,
DataReceivedEventArgs outLine)
{
Process p = sendingProcess as Process;
if (outLine.Data != null)
list.Add(outLine.Data); //Here +s
}
尝试这样的事情。
这里我们创建一个闭包并捕获 locS 值。因此,当事件发生时,我们可以将捕获的值传递给 ProcessOnErrorDataReceived
Search(List<string> path)
{
foreach(var s in path)
{
...
if (process.StartInfo.RedirectStandardOutput)
{
var locS = s;
process.OutputDataReceived += (sender,e) =>
ProcessOnErrorDataReceived(sender, e, locS);
}
}
}
private void ProcessOnErrorDataReceived(object sendingProcess,
DataReceivedEventArgs outLine, string s)
{
Process p = sendingProcess as Process;
if (outLine.Data != null)
list.Add(outLine.Data + s); //Here +s
}