NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Terminate and threads

At a higher level, we have a sequence file that has a MainSequence. The only purpose of MainSequence is to call another sequence "MainThread" in the same file as a STA thread. After calling MainThread, the MainSequence just waits till the MainThread is over. The MainThread launches a GUI through a .NET dll and periodically polls a queue in the GUI to receive any commands. What I am noticing is that most of the time along with other sequences the cleanup of MainThread is called when the Execution.Terminate is called, but there are instances when the MainThread is executing commands, its cleanup is not called. At the same time though I can see the cleanup of MainSequence being called and also I can see the cleanup, being called, of sequences called from MainThread. It's just MainThread's cleanup that is not called.
 
I would like to know why the cleanup of this MainThread doesn't get run?
0 Kudos
Message 1 of 9
(3,558 Views)

Hi,

So is the GUI still running when you are seeing these cleanups run?

Regards

Ray Farmer

Regards
Ray Farmer
0 Kudos
Message 2 of 9
(3,537 Views)

Yes.

 

I though have made one change and it seems to be working. When calling MainThread in MainSequence now I have checked the box to automatically wait for the thread to complete at the end of current sequence. With this box checked now it seems to be calling the cleanup of MainThread now as well.  Any ideas why this check box can make such a difference.

 

Thanks

Ifti

0 Kudos
Message 3 of 9
(3,530 Views)

Hi,

The MainThread sequence needs to complete ie return back from the GUI to allow it to complete and run the Cleanup.

Regards

Ray Farmer

Regards
Ray Farmer
0 Kudos
Message 4 of 9
(3,525 Views)

Thanks.

This requirement would have met even without checking the box in MainSequence. Why does the check box make a difference?

0 Kudos
Message 5 of 9
(3,524 Views)
Hey iftiuk,

In your initial post you said "After calling MainThread, the MainSequence just waits till the MainThread is over."  Perhaps that is the difference between the checkbox making your application works.  It is possible to manually wait for the other thread to complete (besides that checkbox providing this capability "Automatically").  My guess is that something is wrong in that area.  It would seem that if the GUI is still running when MainSequence's cleanup group is executing, you are not waiting properly for the thread to complete.  Note that if you are wanting to wait on this manually, you should store an Object Reference to the thread (in the Settings dialog) and then use a "Wait" step configured to wait on that thread.  This should work.  In any case, you might prefer for this to be automatically handled regardless based on the synopsis of your application.
Thanks,

Andy McRorie
NI R&D
0 Kudos
Message 6 of 9
(3,509 Views)

I had been using Local object reference for the thread and using Wait with that object. But now I am doing both automatically with the checkbox and Wait with object reference. This combination seems to be working so I will stick with this.

Ifti

0 Kudos
Message 7 of 9
(3,506 Views)

The combination is working. I was though able to get more information about the earlier problem.

The issue that I was seeing occured on the timing of Execute.Terminate() being called

The following was the flow

MainSequence calls MainThread in STA thread. MainThread called another sequence 'Alignment' specified in a separate file. 'Alignment' in turn called another sequence 'Load' in a separate file. Load in turn called 'LoadThread' in a separate thread. LoadThread calls a dll function(not the same dll as GUI) which is resposible for loading a file to a device. This loading via dll call takes around 45 to 60 seconds. I encounter the problem only if Termiante is called when this file loading is taking place. Please note that 'Load' and 'LoadThread' are in the same sequence file.

I could see cleanup functions of all these sequences being called except for MainThread.  I could the cleanups for 'Load' , LoadThread and Alignment taking sometime to start probably waiting for the dll call to complete.

Any further ideas regarding what exactly might have been the issue regarding MainThread cleanup not being called.

Ifti

 

 

0 Kudos
Message 8 of 9
(3,501 Views)

Hi,

In summary:

MainSequence calls

          MainThread (Current)(in new thread)

                     calls a dll (GUI)

                      Calls Alignment sequence (seperate seqFile)

                                   Calls Load (seperate seqfile)

                                             Calls LoadThread (Current) (in new Thread)

                                                       Call dll

 

In MainSequence if there is no Wait step in the Cleanup then the Cleanup will be executed once the MainThread has been executed and returned. So this is the first cleanup to be run.

In MainThread, does the call of the dll to launch the GUI return straight away or wait for the GUI to close?

I am assuming it returns straight away to allow Alignment to be called after calling the GUI.

If this is the case, do you have a Wait in MainThread to wait for the GUI to close before completing it's cleanup. If not then MainThreads cleanup will be called once the cleanup of Alignment has completed.

 

Regards

Ray Farmer

Regards
Ray Farmer
0 Kudos
Message 9 of 9
(3,491 Views)