|
-
Feb 24th, 2003, 10:39 PM
#1
Thread Starter
New Member
Monitoring multiple processes for exittime
I have a sub that creates multiple processes and captures the processID and the Startime and addes them to a treeview. My code gives the user the ability to specify how many processes they want to run at a time. The process takes an argument i've extracted from a text file. Say the text file contains a list of 20 computer I want to run my scripts against. The user wants to run 5 processess at a time. Initially the CreateProcess will start the first 5 processes. I've created a timer to periodically check if the any of the processes have had an error or exited and store them. Additionally it would open the next process waiting to be started keeping 5 running at a time until all 20 machines are done. Any ideas? Anyone? This is driving me CrAzY......AAHhhhh
In my "Core" Class is the following:
***************************************************
Friend myprocess as new Process()
Sub CreateProcess(ByVal s As String)
myprocess.StartInfo.FileName = scriptFile
myprocess.StartInfo.Arguments = s
myprocess.EnableRaisingEvents = True
myprocess.Start()
Pid = myprocess.Id
pidStart = myprocess.StartTime
End Sub
Function CheckProcess(ByVal pid As Integer) As Boolean
myprocess = myprocess.GetProcessById(pid)
If Not myprocess.HasExited Then
Return False
Else
pidEnd = myprocess.ExitTime
pidExitC = myprocess.ExitCode
Return True
End If
End Function
In my "main" form is the following timer:
Private Sub tmrCheckComplete_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrCheckComplete.Tick
Dim i As Integer
Dim proc As String
Dim check As Boolean
Dim prnt As TreeNode
'Dim en As System.Collections.IEnumerator = TreeViewProc.Nodes.GetEnumerator
'Dim chkNode As System.Windows.Forms.TreeNodeCollection()
For i = 0 To Al.Count - 1
proc = "PID: " & Al.Item(i)
check = core.CheckProcess(Al.Item(i))
If check = True Then
prnt = TreeViewProc.Nodes(proc).Parent()
core.Complete(prnt)
Al.RemoveAt(i)
Else
'Check next process
End If
Next
End Sub
****************************************************
Ok well I didn't include everything here but you'll get the basic idea. I store the 'ProcessID's in an ArrayList. The problem I'm facing is I know that when I run the
myprocess = myprocess.GetProcessById(pid)
it will error out if the process has stopped because it doesn't exist anymore. I know there is some exception handling but I'm trying to stay away from getting into using exception handling. I understand that long after a process has ended it will keep the 'ExitTime' and 'ExitCode' but I cannot understand how to access that information. I read some things pointing to using the handle instead if the 'ProcessID' but, who knows? I NEED HELP!
Thanks...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|