multiple mode=1 shells...

I have a process that must shell out to the OS to get results.
I have implemented a subclass of Shell that runs in async mode.
depending on the results of the shell more shells may need to be spawned to continue the processes.

This is a hypothetical example and psuedo code.
Say a user has 5 directories for which they must list the directory and its contents.

[code]Proc EventMyShellComplete(s as MyAsyncShell)
dim res as string = s.ReadAll
dim lines() as string
lines = split(res, "
")
for i=0 to lines.ubound
MyShell = new MyAsyncShell
MyShell.Execute(“ls -al” + lines(i))
next
End Proc

Proc dir(lst() as string
for i=0 to lst.ubound // or maximum…
MyShell = new MyAsyncShell
MyShell.Execute("ls -al " + lst(i))
next i
end proc[/code]

This is sort of how it works and it works fine as long as I don’t open too many shells,
and that is the issue I’m trying to solve. How can I limit the number instances of shells that are running?
My Actual code keeps an array of the active shells. i.e. it appends the shell to the array upon creating and removes the shell from the array upon completion.
So lets just say I have a maximum of 10 shells that can be running at a time.

I suspect I need to check the array size before I create a new shell and if its too large I need to sleep and wait for the other active shells to complete before going starting the next shell. But how and where?
I choose async mode because i don’t want my app to freeze while the shell commands are executing…

One way would be to set up a queue and a Timer that periodically checks your array of shells, remove the ones that are done and adds new ones from the queue until the array is “full”.

Perhaps an interactive shell might work better?

If not, it sounds like you want something like the Object Pool Pattern to manage your shells.

I like design patterns!
Timer subclass worked great… solved a whole whack of issues…
Thanks.