473,395 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Process ExitCode error after HasExited true

I am trying to develop some vb.net 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)
alRunningProcessIdList.Add(arrayProcess(i).Id)
Next

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

Do Until alRunningProcessIdList.Count = 0
Thread.Sleep(1000)
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)
alRunningProcessIdList.Remove(arrayProcess(i).Id)
End If
End If
Next
Loop
Else
Console.WriteLine("No processes launched!")
End If
Console.WriteLine("Press <Enter> to exit...")
Console.ReadLine()
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********@oasvas.com.

Thanks,
Dan McGuffin
de********@oasvas.com
Nov 22 '05 #1
0 2436

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dan McGuffin | last post by:
I am trying to develop some vb.net 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...
7
by: Samantha | last post by:
Hello , I am developping a program for Win98 plateform, and I am stucking with a problem, hope you can help me. I have a program running 2 process : - One process running the Xcopy.exe -...
2
by: Tobias Johansson | last post by:
Hello, I'm having what I believe a security problem to execute an executable file from a windows service in windows server 2003. It works fine in WIN XP SP2 The program(the service) itself...
12
by: Raymond Lewallen | last post by:
How to wait for a process to stop completion is my goal. Obviously, the looping while waiting for the HasExited property is not a solution.. but thats the best I can come up off the top of my...
3
by: Zeya | last post by:
I have created a very simple batch file and trying to retrieve the standard output but everytime I run the code it returns ExitCode as 1. I have created a batch file as simple as ping localhost...
11
by: Nurit N | last post by:
This is the third newsgroup that I'm posting my problem. I'm sorry for the multiple posts but the matter becoming urgent. I hope this is the right place for it... I have created a very...
0
by: jamessmb | last post by:
Hello, I have been struggling with this for several days and have searched high and low on both these newsgroups, MSDN and Google. I have the following lines of code which run fine on our...
1
by: tenpsa | last post by:
Hi, I have a C# application that uses the System.Diagnostics.Process functionality to execute other processes (to install a couple of .msi files). Here's my code so far: ...
2
by: =?Utf-8?B?U3RldmVU?= | last post by:
I am trying to get the exit code of an application (IE) after the process closes. On my system I keep getting an exception error. "No process is associated with the object." The Process class is...
1
by: vinayakkatkam | last post by:
public bool ProcessXCopy() { string XCopyArguments = "C:\\Documents and Settings\\Vinayak.Katkam\\Desktop\\SYNCHRONIZATION\\BASE-VERSION\\SDDS\\*.* " + "C:\\Documents and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.