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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop a task in the queued message handler template

Solved!
Go to solution

I am using the basic queued message handler to seperate my event handler and tasks.  An event on the front panel (button pressed) puts a message in the queue.  When the queue handles this message, it performs a task.  However, I now want to add a button on the front panel that immediately terminates this task at any point in the task.  

 

For example:  pressing start on the front panel causes the message handling loop to count up to 10000.  Pressing stop on the front panel should cause the counting to stop.  

 

How can I implement this?

 

Thanks!

0 Kudos
Message 1 of 3
(3,047 Views)
Solution
Accepted by topic author Hiphiphooray

In general you don't want to perform a task in a single frame of your MHL that will take a long time. You have two options:

 

1. Have the MHL message itself to increment the number. That way you can enqueue a priority "stop" message on the queue if you want to stop while this is happening.

2. Have a parallel loop that is incrementing the number, and have the MHL send messages to that loop to start and stop it. Take a look at the Continuous Measurement and Logging sample project for an example of messaging between loops.

Message 2 of 3
(3,031 Views)

Suppose you have a Message that says "Start Counting" and passes in the desired number of counts (say, 10000).  This State initializes the Counter and calls (via a Message on the Message Queue) an "Increment Count" which handles a single count, incrementing the count.  If the count is less than MaxCount, send another Increment Message.  When you finish, you can send a "Finished" message.

 

Note that since you send a Message for every point, you can easily send a Stop message which "sneaks in" and lets you terminate the Count.  Note that when you process the Stop message, you may find that there's a Count message on the Queue -- you can look for this and remove it if you want.

 

This fits the suggestion that processing a Message should not take a long time, making the Message Handler responsive.

 

Bob Schor

Message 3 of 3
(2,981 Views)