Tôi có một tệp thực thi, chạy tốt khi chạy nó theo cách thủ công và nó tồn tại như nó cần với đầu ra dự kiến. Nhưng khi tôi chạy nó với phương thức dưới đây, sự kiện Process.Exited không bao giờ bị sa thải. Chú ý rằng tôi đã nhớ lại Process.EnableRaisingEventsProcess.Exited không bao giờ được gọi, mặc dù EnableRaisingEvents được đặt thành true
protected override Result Execute(RunExecutable task)
{
var process = new Process();
process.StartInfo.Arguments = task.Arguments;
process.StartInfo.FileName = task.ExecutablePath;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.EnableRaisingEvents = true;
process.Exited += (sender, args) =>
{
processSync.OnNext(new Result
{
Success = process.ExitCode == 0,
Message = process.StandardOutput.ReadToEnd()
});
processSync.OnCompleted();
};
process.Start();
return processSync.First();;
}
Vấn đề là như nhau, nếu tôi sử dụng Process.WaitForExit() thay vì mở rộng phản ứng, chờ đợi cho sự kiện thoát.
Ngoài ra, nếu tôi chạy quy trình với một đối số khác, tạo ra một kết quả khác, nó tồn tại tốt.
Dường như có liên quan gì đó đến số process.StartInfo.RedirectStandardOutput = true;
kể từ khi tôi tắt tính năng này, nó hoạt động. Nhưng đó có thể chỉ là một triệu chứng của một vấn đề khác.
Bất kỳ trợ giúp nào được đánh giá cao :-)
Arh, giải thích điều đó! Cảm ơn :-) –