I'm checking if its possible to make C# run subversion commands and print each output in a listbox. On a button click I have:
ProcessStartInfo cmd = new ProcessStartInfo("cmd.exe", @"/k svn update D:\MyProject");
cmd.CreateNoWindow = true;
cmd.RedirectStandardOutput = true;
cmd.RedirectStandardError = true;
cmd.WindowStyle = ProcessWindowStyle.Hidden;
cmd.UseShellExecute = false;
Process reg = Process.Start(cmd);
using (System.IO.StreamReader myOutput = reg.StandardOutput)
{
output = myOutput.ReadToEnd();
}
using (System.IO.StreamReader myError = reg.StandardError)
{
error = myError.ReadToEnd();
}
lsbOutput.Ite开发者_如何学运维ms.Add(output + Environment.NewLine + error);
}
The issue is that the process is Synchronous, because when StreamReader
is reading output, it could take a long time. Listbox is taking the output only when svn update
is finished.
I would like to know if there is a way to update on-the-fly getting and printing each output response right away, instead of waiting the whole process to be completed.
Maybe I should use something like http://sharpsvn.open.collab.net/
Read output and error streams line by line in a different thread:
string line;
while ((line = reader.ReadLine()) != null)
{
worker.ReportProgress(0, line);
}
using http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
精彩评论