Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Single Instance of an Actor/Only Launch if not running

Solved!
Go to solution

I have actor for each the popup windows in my system and I don't want 2 of the same popup on screen.

Lets say I have a Configure Test Popup.  If press "Configure Test" button on my main application (the caller) and it launches the Configure Test Popup nested actor.  The Test Popup actor stays on screen. 

If I press the "Configure Test" button again whilst the popup is still on screen, I don't want another popup to be displayed.

If I have closed the Configure Test Popup then I do want another nested actor to be launched when I press the "Configure Test".

At the moment, I have a message for my caller that launches the popup and stores the Enqueuer.

Capture.PNG

I have tried using the "Message Enqueuer:Equals Not A Refnum" and only launch if it is a valid refnum.  this doesn't work because it stays valid even once the Actor has closed.

I was thinking about using the Last Ack so I know once the actor has closed and whether to re-launch or not.

Any thoughts would be great.

Cheers

Lewis


0 Kudos
Message 1 of 12
(6,429 Views)

I could also always have the popup actos running and then have a show/hide method. To close the front panel or show the front panel.

I think this might be the best

0 Kudos
Message 2 of 12
(4,913 Views)

Some options:

  1. Have this protection in the caller, as that's where it makes sense, because that's where you launch the actor. This appears to be what you have now.
  2. Instead of launching the actor each time you want it, launch it once at the beginning of the caller and then pass it an "open" message when you want it to open its FP. I guess from your description that it decides when to close the FP, but it doesn't stop at that point. You stop the actor at the end of the caller. Edit - I see you came to the same conclusion.
  3. Just use a modal dialog for the configuration. Might not be relevant in your case.

___________________
Try to take over the world!
Message 3 of 12
(4,913 Views)

Here is what I would do.

Store a boolean in the caller for whether the nested actor is launched. When you receive a request to launch the nested actor only launch if the boolean is false. When you launch set it to True. When you receive last ack set it back to false.

Casey

Casey Lamers


Phoenix, LLC


casey.lamers@phoenixwi.com


CLA, LabVIEW Champion


Check Out the Software Engineering Processes, Architecture, and Design track at NIWeek. 2018 I guarantee you will learn things you can use daily! I will be presenting!

0 Kudos
Message 4 of 12
(4,913 Views)

Lewis_G wrote:

...this doesn't work because it stays valid even once the Actor has closed.

The message queue should die with the Actor, so this should work (unless there is a bug somewhere).

-- James

0 Kudos
Message 5 of 12
(4,913 Views)

drjdpowell wrote:


The message queue should die with the Actor, so this should work (unless there is a bug somewhere).

I haven't tested, but all the VI does is compare the enqueuer to a constant. Presumably any initialized NQR is different from the constant, even if it was closed (since it's simply by-value).


___________________
Try to take over the world!
0 Kudos
Message 6 of 12
(4,913 Views)

tst wrote:

I haven't tested, but all the VI does is compare the enqueuer to a constant. Presumably any initialized NQR is different from the constant, even if it was closed (since it's simply by-value).

That's not consistant with what "Not a Refum" means for other LabVIEW references.  A dead Queue/Notifier/DVR/etc. is is "Not a Refnum" even if it is a non-zero number. 

0 Kudos
Message 7 of 12
(4,913 Views)

drjdpowell, this is correct. "Not a refnum" for NQRs is not consistent with other LabVIEW references. It says so in the documentation:

This function only checks whether Message Enqueuer is equal to Not a Refnum. It does not check whether Message Enqueuer still is valid because doing so can introduce a race condition into the application. It is possible for a refnum to become invalid after being declared valid but before a message is sent to it.

"Wisdom comes from experience. Experience is often a result of lack of wisdom.”
― Terry Pratchett
0 Kudos
Message 8 of 12
(4,913 Views)

Yes,  I can confirm that this does not work..

Capture.PNG

You do get an error when you send the Stop message because the Enqueuer is no longer valid (if I have shut down the nested actor).  So the only way to do it would be to send a message that does nothing?  If it doesn't error on the Enqueue then the actor is running.  If it does error, the actor has been stopped.

0 Kudos
Message 9 of 12
(4,913 Views)
Solution
Accepted by topic author lewboi

The solution I've gone for in the end is having a parent actor which has a Launch Abstract Popup Method and Overrides Handle Last Ack.

Launch:

launch.PNG

Handle Last Ack.

handle last ack.PNG

Stop Core also shutdowns any popups left open.

This seems to work really well.  Any actor that overrides my process actor can launch a popup and not worry about keeping track of references.

thanks for the help

0 Kudos
Message 10 of 12
(4,913 Views)