Vin*_*ent 9 .net c# cgi process
我试图从.NET程序调用php-cgi.exe.我使用RedirectStandardOutput将输出作为流返回,但整个过程非常慢.
你对我如何能加快速度有任何想法吗?还有其他技术吗?
Dim oCGI As ProcessStartInfo = New ProcessStartInfo()
oCGI.WorkingDirectory = "C:\Program Files\Application\php"
oCGI.FileName = "php-cgi.exe"
oCGI.RedirectStandardOutput = True
oCGI.RedirectStandardInput = True
oCGI.UseShellExecute = False
oCGI.CreateNoWindow = True
Dim oProcess As Process = New Process()
oProcess.StartInfo = oCGI
oProcess.Start()
oProcess.StandardOutput.ReadToEnd()
Run Code Online (Sandbox Code Playgroud)
Jad*_*ias 17
我发现的最佳解决方案是:
private void Redirect(StreamReader input, TextBox output)
{
new Thread(a =>
{
var buffer = new char[1];
while (input.Read(buffer, 0, 1) > 0)
{
output.Dispatcher.Invoke(new Action(delegate
{
output.Text += new string(buffer);
}));
};
}).Start();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
process = new Process
{
StartInfo = new ProcessStartInfo
{
CreateNoWindow = true,
FileName = "php-cgi.exe",
RedirectStandardOutput = true,
UseShellExecute = false,
WorkingDirectory = @"C:\Program Files\Application\php",
}
};
if (process.Start())
{
Redirect(process.StandardOutput, textBox1);
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用OutputDataReceived事件接收数据,因为它被泵送到StdOut.
归档时间: |
|
查看次数: |
17116 次 |
最近记录: |