LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Functional "Close all Open VIs when Main VI closes" Example

Solved!
Go to solution

I've searched through this forum and various knowledge base articles and I've yet to find a functional example on how to close all open SubVIs when a Main VI is closed by clicking the close button (X in the upper right corner of the Window). I've tried a few things using event structures, but I haven't been able to produce the results that I would like. I would really like all open VIs to close when the Main VI is closed. I know I could simply disable the close button and get the results I want, but I want to keep that option available. 

 

Essentially I have a program that runs and depending on user input, another window can open to adjust program settings etc. Only one window other than the Main VI is open at a time. If the user decides to close the Main VI while another window is open, I would like all windows associated with the Main VI to close with the Main VI. 

 

Is this possible? Does anyone have a simple example they are willing to share? 

0 Kudos
Message 1 of 16
(3,115 Views)

There is an example that ships with LabVIEW called "Dynamically Monitor VI's" that uses User Generated Events.  This may give you an idea how to do this. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 16
(3,088 Views)

Thank you for the Reply.

I suppose that I should have added that I am using LabVIEW 2019 in the original post. I wasn't able to find any files or folders called "Dynamically Monitor VI's" on my LabVIEW 2019 install. 

0 Kudos
Message 3 of 16
(3,077 Views)

Look up User Events.  You can then just pass the User Event reference into your called window and have it register for the event.  Handle that event in your Event Structure of your called window to close/stop the VI.  On your main VI, you just send that User Event when the panel is closed.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 16
(3,053 Views)

Yeah, that VI/LLB is from an older version of LabVIEW.  I would share it if I knew it was ok to share LabVIEW examples.  

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 5 of 16
(3,050 Views)
Solution
Accepted by topic author aanderson

There are two questions here -- one is how to properly handle the "Application Close?" X in the upper right corner of your Main VI, and the second is how to arrange all of your VIs such that the Main can tell all of the others to stop.

 

If you stop your Main by pushing a Stop Button on your Front Panel, which cause the Main routine to go into its "Shutdown and stop" routine, it should reach out to all the other VIs and tell them to stop.  So how to handle the Big Red X?

 

Create a User Event and have it handle the event Application Instant Close? (which is an Application Event).  This "fires" when you push the X.  You want to wire "True" to the "Discard?" terminal because you do not want Windows to close your routine, you want LabVIEW to do it.  So do whatever you would ordinarily do by pushing a Stop button and having an Event catch that action and start the Shutdown.  Here's an example from one of my routines (I'm using a Message Handler, and I'm sending the "Stop" message to the Message Handler Loop, which tells everyone else to quit).Application Instance Close? EventApplication Instance Close? Event

Bob Schor

Message 6 of 16
(3,003 Views)
Solution
Accepted by topic author aanderson

@Bob_Schor wrote:

There are two questions here -- one is how to properly handle the "Application Close?" X in the upper right corner of your Main VI, and the second is how to arrange all of your VIs such that the Main can tell all of the others to stop.

 

If you stop your Main by pushing a Stop Button on your Front Panel, which cause the Main routine to go into its "Shutdown and stop" routine, it should reach out to all the other VIs and tell them to stop.  So how to handle the Big Red X?

 

Create a User Event and have it handle the event Application Instant Close? (which is an Application Event).  This "fires" when you push the X.  You want to wire "True" to the "Discard?" terminal because you do not want Windows to close your routine, you want LabVIEW to do it.  So do whatever you would ordinarily do by pushing a Stop button and having an Event catch that action and start the Shutdown.  Here's an example from one of my routines (I'm using a Message Handler, and I'm sending the "Stop" message to the Message Handler Loop, which tells everyone else to quit).Application Instance Close? EventApplication Instance Close? Event

Bob Schor


I would recommend using the Panel Close? event instead. The Application Close? Event should fire in an EXE, but not in the development environment (IDE).

 

mcduff

Message 7 of 16
(2,992 Views)

I wish I could give both @Bob_Schor the credit as well for putting me on the right track.  

Edit: I guess you can accept multiple solutions. Thanks all.

 

I had been testing this in the development environment and was pulling my hair out not getting this to work with the "Application Close?" event rather than the "Panel Close?". It is behaving how I expect it to now. 

 

Thank you both for the help. 

0 Kudos
Message 8 of 16
(2,984 Views)

@mcduff wrote:

I would recommend using the Panel Close? event instead. The Application Close? Event should fire in an EXE, but not in the development environment (IDE).

It works equally well in Development and Execution Environments.  I learned this Piece of Wisdom from a "Fab"ulous LabVIEW Champion (whose name I am conveniently forgetting).  She (hint!) gave a wonderful presentation at NIWeek 4-5 years ago that had many words of wisdom, including the Wisdom of Always Using a Time Machine (a.k.a. Version Control Software).   But I knew that ...

 

Bob Schor

Message 9 of 16
(2,952 Views)

@Bob_Schor wrote:

@mcduff wrote:

I would recommend using the Panel Close? event instead. The Application Close? Event should fire in an EXE, but not in the development environment (IDE).

It works equally well in Development and Execution Environments.  I learned this Piece of Wisdom from a "Fab"ulous LabVIEW Champion (whose name I am conveniently forgetting).  She (hint!) gave a wonderful presentation at NIWeek 4-5 years ago that had many words of wisdom, including the Wisdom of Always Using a Time Machine (a.k.a. Version Control Software).   But I knew that ...


I have never used a Time Machine before because I could never figure out how to use it properly and I didn't really understand the concept.  Unfortunately, this was not taught in my university.  But I found a video from Fabiola this morning.  Wow...what a great video explaining how to setup TortoiseSVN and how to use it.  This will be my next task.  

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 10 of 16
(2,917 Views)