I am attempting to work out the code syntax for waiting until a thread is complete before moving on. I have tried to follow the language ref but I’m missing the boat on this one. ProgramThreadSequencer is the thread in mainwindow. I have tried these:

While mainWindow.ProgramThreadSequencer.ThreadStates = ProgramThreadSequencer.ThreadStates.Running

While mainWindow.ProgramThreadSequencer.ThreadStates.Running

While mainWindow.ProgramThreadSequencer.ThreadStates = ProgramThreadSequencer.Running

While mainWindow.ProgramThreadSequencer.running

Probably more like

While mainWindow.ProgramThreadSequencer.ThreadState = Thread.ThreadStates.Running

you cant correctly reference the ENUM using the instance
its tied to the class definition itself

EDIT : this said I wouldnt wait this way as the while loop is so busy it will give you a pinwheel
I’d use the events of the thread to know when to move on tho “the next step” that you might have in each loop etc

What is it that will be waiting until a particular thread completes? Another thread? If that’s the case then have the waiting thread suspend itself, and have the running thread resume it as it completes.

As @Norman Palardy says, don’t loop like that. If you think you must loop, at least have in the loop a call to sleep for some msec, such as:

app.SleepCurrentThread (10)

If you just loop, you’ll probably use all the CPU and prevent your other thread from completing.

I am opening another window that will be used to send output serial commands to an interface controller. The thread which repeatedly runs to collect data from the interface and sends commands to the interface will cause conflicts if also running. When I open the output window I need to wait until the thread has completed its cycle before sending other output commands. I also suspend the tread at that time. Sleeping the thread or pausing it does not work since it loses track of the command sequence structure to the interface. The sequence has been altered by using the output window.

Of the various thread states, only one means it’s finished and that is NotRunning. Any other state means that it’s still active. And be sure to yield inside your loop.

while mainWindow.ProgramThreadSequencer.ThreadState <> Thread.ThreadStates.NotRunning

How might you “wait” for the completion of the thread without hogging things down such as mentioned by others?

The best solution is “don’t”. Break up your code into sections and have the thread raise an event or fire a short-period timer that executes the rest of your code.