在单独的线程上执行进程会导致System.IO .__ Error.WinIOError [英] Executing a process on separate thread results in System.IO.__Error.WinIOError

查看:1302
本文介绍了在单独的线程上执行进程会导致System.IO .__ Error.WinIOError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个基本的GUI应用程序,该应用程序本质上会在给定某些参数的情况下调用其他进程,同时这些应用程序的输出会通过RTF框实时显示给用户.因此,基本上,我有一个单独的进程线程来运行子进程.

I'm writing a basic GUI application that essentially invokes other processes given some parameters, while the output of those applications is displayed to the user via a richtext box in real-time. So basically I have a seperate process thread running the child processes.

除xdiscbld.exe(Xbox ISO映像创建器工具)崩溃,大多数进程在该线程上都能正常工作,

Most of the processes work fine on that thread, except for xdiscbld.exe (an Xbox ISO image creator tool) which crashes saying:

Unhandled Exception: System.IO.IOException: The handle is invalid.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.Console.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
at System.Console.get_BufferWidth()
at XDiscBld.XDiscBldProgram.ProcessDisc()
at XDiscBld.XDiscBldProgram.Run(String[] args)
at XDiscBld.XDiscBldProgram.Main(String[] args)

(顺便说一句,通过命令提示符或单线程Process调用,xDiscBld运行正常)

(BTW, xDiscBld runs fine via a command prompt, or single threaded Process call)

我通常不会发布这样的特定错误,但是我真的很困惑,我认为这可能与线程的常见问题以及某些IO句柄有关.如果任何人有类似问题的经验或对此有任何见识,都将被推荐.

I wouldn't normally post such a specific error, but I'm really stumped and I think it could be something generic pertaining to a common issue with threads and holding onto some sort of IO handle. If anyone has had any experiance with a similar problem or has any insight on this, it would be appriciated.

推荐答案

我认为实际的问题与线程无关,但是XDiscBld希望写入不存在的控制台窗口.这是因为我正在开始这样的过程.

I believe the actual issue doesn't have to do with threads, but rather XDiscBld wants to write to a console window that doesn't exist. This is because I'm starting the process like this.

process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = false;
process.StartInfo.FileName = FileName;
process.StartInfo.Arguments = Arguments;
process.StartInfo.WorkingDirectory = WorkingDirectory;
process.Start();

如果我只跑

process.StartInfo.FileName = FileName;
process.StartInfo.Arguments = Arguments;
process.StartInfo.WorkingDirectory = WorkingDirectory;
process.Start();

有效.因此,它不喜欢我如何重定向输出.话虽如此,我仍然不知道如何在现有系统的情况下完成这项工作.由于该主题已严重出轨,我想我应该删除它并重新开始,或者留给他人参考.

it works. So it's not liking how I'm redirecting the output. With that said, I still don't know how to make this work with the current system in place. Because this topic has derailed horribly I guess I should either delete it and start over, or leave it up for others' reference.

这篇关于在单独的线程上执行进程会导致System.IO .__ Error.WinIOError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆