我使用Parallel.ForEach
来运行多个进程。所有工作正常,但是在某些情况下,我不了解Process_1
的行与Process_2
的行显示在同一行,等等。 ...我使用2个功能来增加时间,另一个使用功能来过滤数据并添加颜色。我的最后一个功能可以完成工作,但是我认为没有时间在行尾之前写...在控制台显示下方:
[21:30:12] > Process_1 [21:30:12] Verification > Ok... Process_2 > Verification Number Ok.. > hole(s) Number : 561 hole(s) : 561
我希望得到所有结果:
[21:30:12] > Process_1 Verification Ok... > Number hole(s) : 561
[21:30:12] > Process_2 Verification Ok... > Number hole(s) : 561
我的代码:
Parallel.ForEach(mydir, options, Sub()
Dim form As New Process()
...
...
form.Start()
While form.StandardOutput.EndOfStream = False
Dim output As String = form.StandardOutput.ReadLine()
ConsoleWriteLog(output)
End While
form.Close()
End Sub)
Sub ConsoleWriteLog(ByVal output As String)
Dim LogTime As DateTime = Now
Dim T As String = LogTime.ToString("[H:mm:ss]")
output= T & " > " & output
ColorData(output, T)
End Sub
Sub ColorData(ByVal output As String, ByVal w As String)
Dim substrings As String() = output.Split()
For Each substring As String In substrings
If substring.Contains(w) Then
Console.ForegroundColor = ConsoleColor.DarkYellow
End If
Console.Write(substring & " ")
Console.ResetColor()
Next
Console.WriteLine()
End Sub