Piotr,
I have a problem with HasExited process property.
The error is :
System.InvalidOperationException: Process has exited, so the requested
information is not available.
Some of the properties of the Process calls are not available after the
associated process has exited, and ProcessName is one of those. So you
should cache that value to another variable before the process has exited.
Another thing. How are you constructing the Process object, and how are you
starting the associated process? I often find that people seem to miss the
fact that most of the overloads of the Start() method are static and return
a new process object. This can cause trouble, as you are then possibly
manipulating the wrong object instance.
The following piece of errorneous code for example causes the
System.InvalidOperationException you mentioned:
--------------------------
Process p = new Process();
Process.Start(@"C:\App\SomeApp.exe"); // wrong; static method returns new
Process object
Console.WriteLine("HasExited = "+p.HasExited); // exception here
Console.WriteLine("Name = "+p.ProcessName);
--------------------------
The correct way would be to assign the return value of the static Start()
method to "p", instead of creating a new Process instance with a call to
"new".
Hope this helps.
--
Regards,
Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi http://www.saunalahti.fi/janij/