views:

1346

answers:

2

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.

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)

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

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.

A: 

What's happening here is that the handle you are using from that process is invalid. There are a couple of reasons this could occur, most common is that the process has already exited thus invalidating the handle.

JaredPar
Jared, that looks like it's failing in the Console.BufferWidth getter, so I think it's the handle to the console that it's complaining about.
John Saunders
A: 

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();

If I run with just

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.

Balk
Did you try reading the redirected outputs? You must. See http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput.aspx.
John Saunders