about shells and threads....

I have a method that needs to shell out to get results.
I started by making a subclass of Thread called MyCommand.

In the ‘run’ method I created a new shell and used it in mode 0.
When the shell returned I raised an event to signal the thread had completed.

In the threadcomplete event handler I created another instance of MyCommand that takes the results of the previous command and then shelled out again to process the new command. Depending on the results of the first command there maybe dozens of subsequent commands to be executed.

During this process I am trying to update a progress bar on my application… i did this in the event handler of thread completed.

The result of all this is that the progress bar never got updated… It seems that the UI only gets updated when the last of the shells is completed.

My thought was … well let me get rid of the thread and try using mode 1 of the shell and update the UI when there is data available or when the command has completed…

So rather than create a second instance of MyCommand when the first completes I though maybe in the command completed event of shell I can simply execute the next command(s). Still I’m not convinced that I will solve my GUI update problems with this change.

Any thoughts? Timers etc?

P.S. These commands may take a few seconds each to complete…

For what you’re doing, you’re better off subclassing Shell, using mode 1, then using a stage enum or some other method to track your progress and have DataAvailable proceed to the next step. You can update your progress bar directly from that.

A thread with a mode 0 shell is useless. Use a mode 1 shell and no threads. The shell will not impact your app at all.

I’m curious about how chaining commands in the shell completed event will affect things…
I suppose that if I execute another command in the completed event that the command will continue on asynchronously…

Is there perhaps a DoEvents that might be necessary?

No, because the shell is executing, and calling DataAvailable, during idle time, so other events are taking place until DataAvailable fires.

So must one implement something In dataavailable or can the event be ignored and the data read at the complete event?

If memory serves, one of those doesn’t fire with mode 1. But do it in Completed if it does.

For Shell.Mode = 1 all the data in Shell.Result can be read upon completion in the Shell.Completed event without need to incrementally read data in the Shell.DataAvailable event.