توجيه الإخراج القياسي بكفاءة في .صافي
سؤال
أنا أحاول الاتصال php-cgi.exe من .برنامج NET.يمكنني استخدام 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()
المحلول
ويمكنك استخدام OutputDataReceived الحدث لاستقبال البيانات كما انها تضخ إلى المعياري.
نصائح أخرى
والحل الأفضل لقد وجدت هو:
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);
}
}
المشكلة هي بسبب سوء php.ini التكوين.كان عندي نفس المشكلة و أنا تحميل ويندوز المثبت من: http://windows.php.net/download/.
بعد هذا التعليق لا حاجة ملحقات عملية التحويل alà Speedy Gonzales, تحويل 20 php في الثانية.
يمكنك استخدام بأمان "oProcess.StandardOutput.ReadToEnd()".هو أكثر قابلية للقراءة و alomost بأسرع باستخدام خيط الحل.استخدام الخيط الحل بالتزامن مع سلسلة تحتاج إلى تقديم حدث أو شيء.
هتافات
لا تنتمي إلى StackOverflow