In terms of LabVIEW Actor Framework, Helper Loop – is loop which runs in parallel to Actor Core, and is used to handle either time-consuming code (which could potentially block Actor), or handle Event Structure events.
While using Helper Loop, develop must ensure that it is properly stopped, because this is common reason of “freezing” actors – when Actor Core is stopped, but helper loop is still running.
So let me share one approach of how that could be implemented. This is not something new and for sure familiar for those who already use AF for some time, but hope that it could be useful for newcomers to AF.
In my application, most of the time there are Helper Loops which handle Event Structure – those are mostly GUIs actors. So I’m going to use dedicated User Event to stop Helper Loop. And, let’s try to implement it in reusable way – so potential childs of this actor would have this functionality implemented, and we will not need to implement Helper Loop stopping all the time.
What should be stopping order? I’d recommend to stop Actor itself first, and after is has been stopped – stop Helper Loop.
As Stop Core.vi will be the only place from which Helper Loop is stopped, then there is no need to expose User Event reference via data accessor to other classes, we could keep it privately.
But, there will be need to register User Event to specific Event Structure in the Actor Core. For this purpose, it will be enough to register User Event in Pre Launch Init.vi, store registered reference in Actor’s private data, and then read it using data accessor.
So let’s go to the implementation.
First, let’s override Pre Launch Init.vi.
Then, let’s override Stop Core.vi.
And finally, there is needed Read data accessor for registration refnum (I’ve marked it as Property Node, and as private).
Base UI Actor is ready – now it is possible to implement specific child class, which will have simple GUI, Helper Loop and that Helper Loop will be stopped using logic from parent’s actor.
For that, let’s add Simple UI actor, and set Base UI Actor as its parent. After, simple UI should be implemented by overriding Actor Core.vi.
StopHelperLoop is registered, and Stop flag is set. And, pressing on Stop button should just send Normal Stop message, without setting of Stop flag for Helper Loop.
That’s it – quite simple, but I believe that reusable approach, because no need to duplicate everywhere code of user event creating, registering and generating.
If you are interested in source code, it is available at github by the following link. Source code is done in LabVIEW 2020.