tags:

views:

98

answers:

2

Hi:

I have a loop that spawn new process to run some ".exe" files. And I capture the output of those ".exe" files to my textbox. In order to capture the outputs right away, I can't use process.waitforexit() method. The problem I have right now is if the previous process took a long time to run, a second process will run regardless if the previous one finished or not. This messed up my outputs.

Is there a way for me to insert the processes into a queue structure so it can be run in a sequential order?

Thanks

+2  A: 

Sure:

Queue<Process> processes = GetProcesses();
while(processes.Count > 0) {
    Process process = processes.Dequeue();
    // execute process and capture output
}

Here's MSDN on Queue(T).

Jason
If I understand correctly, getProcesses creates an array of new Process components and associates them with existing process resources. However, I just want the process I created in the loop to be in the queue. How should I initialize the queue in this case?
`GetProcesses` is your function for populating the queue. Use `Queue.Enqueue` to add the processes that you create to the queue.
Jason
Thanks Jason, I will try this.
A: 

You could also run the processes parallelly in threads and queue only the output.

However, you would have to use a more complicated locking and notification system.

winSharp93