From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use notification with parallel thread

Solved!
Go to solution

Hi,

I am learning to use Notification to communicate between thread. I still don't know how to use it. In my current project I have a case to use this so I think I should implement this technique. My example is I have a main sequence in that I make a new thread. What I want is the new thread will do a task A when receive a notfication or to exit the thread when the main sequence stop.

I am not sure if using notification is a best practice here? Or should I use a reference data?

What about if I want my thread to do task B if it receive another notification. Is notification still be helpful?

 

Regards,

Thang Nguyen

0 Kudos
Message 1 of 5
(5,368 Views)

Hello,

 

You can use Notification to handle parallel threads. I often create two sequences : one containing the process A of your example (StartProcessA). and a second one to stop this process (StopProcessA). In StartProcessA, I create a Notification, with a defined name (as string constante, "StopProcessANotifier" for instance) in the setup group. Then I have the process, in a loop. At the end of this loop, I check the Notification (Wait) with a  timeout enabled, and no error if a timeout occurs. this way, the Notification Wait can be used as loop timing, and if the notification is Set in MainSequence, this exit the loop (pick a look at Notification property Step.Result.TimeoutOccured).

 

To sum up, use a first sequence call in MainSequence, calling StartProcessA, with NewThread option, and do not forget to call StopProcessA at the end of you MainSequence. The Cleanup group is a very good location, because it will be executed even in case of error.

 

This is a very simple use of Notification. Note, I believe that make it simple is often the most important but also the most complicated thing to do Smiley Wink

 

Hope this helps....

0 Kudos
Message 2 of 5
(5,363 Views)

Mathieu,

Thank you for your reply.

Could you please tell more specific how to set up the notification? Or it will be best if you have a sample code. Is it based on the string name of the notification? As I understand, in the parallel sequence you create a notification and wait for the event from this notification. On the main sequence you just use only a notification step with the identification string name with the same with the one  create inside the parallel sequence and set event to it. Am I correct? 

 

Regards,

Thang Nguyen

0 Kudos
Message 3 of 5
(5,354 Views)
Solution
Accepted by topic author NTT

That's correct, you can call the Notification - Set directly from the MainSequence indeed.

 

Here is a example : the sequence StopProcessA is not absolutely required - it is just for modularity purposes.

 

Best regards,

Message 4 of 5
(5,349 Views)

Mathieu,

Thank you for your sample code!


Regards,

Thang Nguyen

0 Kudos
Message 5 of 5
(5,346 Views)