By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,471 Members | 722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,471 IT Pros & Developers. It's quick & easy.

Process ExitCode error after HasExited true

P: n/a
I am trying to develop some code that will will store 1 or more processes in an array of processes, then loop through the array determining when each one has exited. Upon each one exiting, I want to display the corresponding process' exitcode. I had the following code working a week ago, but then I made some (mostly) cosmetic changes, and now I can't get it to work.

Imports System
Imports System.Collections
Imports System.Diagnostics
Imports System.Threading

Namespace Process_Sample
Class MyProcessClass
Public Shared Sub Main()
Dim myProcess As Process

myProcess = Process.Start("notepad")

Dim arrayProcess As Process() = Process.GetProcessesByName("notepad")

If arrayProcess.GetUpperBound(0) >= 0 Then
Dim alRunningProcessIdList As New ArrayList
For i As Int16 = 0 To arrayProcess.GetUpperBound(0)
Console.WriteLine("Process id {0} started at {1}", arrayProcess(i).Id, arrayProcess(i).StartTime)

Console.WriteLine("processes launched = {0}", (arrayProcess.GetUpperBound(0) + 1))

Do Until alRunningProcessIdList.Count = 0
For i As Int16 = 0 To arrayProcess.GetUpperBound(0)
If alRunningProcessIdList.Contains(arrayProcess(i).Id ) Then
If arrayProcess(i).HasExited Then
Console.WriteLine("Process Id {0} has exited", arrayProcess(i).Id)
Console.WriteLine("with an exit code of {0}", arrayProcess(i).ExitCode)
End If
End If
Console.WriteLine("No processes launched!")
End If
Console.WriteLine("Press <Enter> to exit...")
End Sub
End Class
End Namespace

The output I get in the console window is:

Process id 1068 started at 1/28/2004 4:29:09 PM
processes launched = 1
Process Id 1068 has exited

The program throws an exception on the line highlighted in red above. The error message is:

"An unhandled exception of type 'System.InvalidOperationException' occurred in system.dll

Additional information: Process was not started by this object, so requested information cannot be determined."

If anyone can help me, I would greatly appreciate it. Please reply to this post, or to de********

Dan McGuffin
Nov 22 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.