开发者

Process reuse - async BeginOutputReadLine problem

I've encountered an interesting problem.

C# allows reusing process resource (according to MSDN) - so I call instance Start() method after process is finished:

Process p = 开发者_StackOverflownew Process();
// init
p.Start();

And some time later:

p.Kill();
// not important
p.Start();

When I have a thread performing sync read everything seems to be ok - output is being read after first and second Start() call.

Now the funny thing. When I use async read (everything initialized properly):

p.BeginOutputReadLine();

output is being read only after first Start() call. After second call process is started without any output being redirected.

I've also tried calling Cancel and Begin once more:

p.CancelOutputRead();
p.Kill();
// not important
p.Start();
p.BeginOutputReadLine();

with same result.

Some machine details: Win 7 Ultimate x86 SP1 (CPU also x86), tested on .NET 2.0 / 3.0, VS 2008

The question is - is it some framework bug or my misunderstanding of the Process.Start definition ("Starts (or reuses) the process resource that is specified by the StartInfo property of this Process component and associates it with the component.")? Any help much appreciated.

I suppose the solution is recreation of the process object, but it'll probably be slower.


Calling Kill makes it necessary to add your event handler for OutputDataReceived again before calling Start.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜