NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to call a sequence in a new thread from C++ dll

Here is what I am trying to do:
I implemented a dll that monitors network traffic, and it also supports message handlers that can be triggered when a specific message has been received. Essentially the receipt of a message is like an event causing additional code to be executed. What I need to do is have the message handler in the dll call/execute a sequence (either is the same sequence file that originally called the dll, or in a different sequence file). Also I want the sequence to be executed within the same execution object for the purpose of result collection and report generation. I am expecting the dll to have to launch a new thread to call a sequence because of the asynchronous nature of the message received event.
 
There are easier ways to achieve the same result, but one of my goals is to make it easy for a test developer to configure a message handler, by having only one step in their sequence to configure the message handler. I want the rest to be transparent to the user.
 
I am unsure about how to implement this feature, so I am asking for any examples, ideas, comments before I start trying things out.
0 Kudos
Message 1 of 3
(3,526 Views)
Assuming that I understand your question correctly, it would seem to be the best way to do this would be to pass the Execution object to the DLL (either through a direct pass of the Execution object or passing the sequence context, from which you can get the Execution).  Then simply call Execution.NewThread, specifying the SequenceFile object (accessible from Engine.GetSequenceFileEx) and then passing the Thread object out as an output.  Your sequence file in which your DLL is called could then simply have a Wait step which is configured to wait on that Thread object.  What happens in this case is that the results are collected for that thread (which is being executed asynchronously) and returned as the results for the Wait step.

Although you are probably not using LabVIEW, I have attached an example of this in LabVIEW that might be helpful just for seeing the flow.
Thanks,

Andy McRorie
NI R&D
Download All
0 Kudos
Message 2 of 3
(3,510 Views)
Thanks. I took a look at the VI and also figured out that Execution.NewThread is new for TestStand 4.0. Looks like I need to upgrade from 3.5 to 4.0 before I go any further.
0 Kudos
Message 3 of 3
(3,495 Views)