Tuesday, December 11, 2007

"Application Instance Close" Events


One of my friends recently asked me how to create a VI that runs in the background and shuts itself down when LabVIEW exits (without prompting the user to abort running VIs).

After a little research, we determined that the answer was using the "Application Instance Close" events.

This is a somewhat advanced topic, but using both the filter and notify Application Instance Close events achieves the desired effect.

If you want to see this in action, watch this video.

[Edit January 15, 2008] I need to underscore that this technique is needed when a VI is running as part of the LabVIEW editor. For normal applications, you do not want to suppress the "abort running VIs?" prompt because you want users to shut down a VI from its user interface.

Labels:

3 Comments:

Anonymous Henrik Skupin said...

Nice to see that you continue blogging after such a long period of time. And it's a great post you started with. Nice to see what's possible with event cases. Never had the idea to solve it in such a way.

But IMO that mainly applies to VIs which are handling front panel elements and using an event structure. If your background VI doesn't use such an event structure e.g. only acquiring measurement data or something else it won't work. In such cases I use a notifier which can be easily shared between different threads or VIs. If the application closes, the main thread also destroys the notifier which will be seen by each reader of that notifier. Than you can normally run your shutdown tasks for each thread without having to think about where it has to be placed to get executed.

4:34 AM, December 13, 2007  
Blogger Christina said...

Hi Henrik,

I like your architecture, if you're writing an application where you control the shutdown of the VIs.

I probably should have stressed more in my original post that the Application Close events are useful when you need to have a VI running in the LabVIEW editing environment that needs to shut down when LabVIEW exits.

The question that prompted this post was from a friend who needed a VI to run invisibly in the LabVIEW editing environment. The user wouldn't even know it was there, so it was important not to get the "abort running VIs?" prompt when the user selected File>>Exit.

The filter event for Application Instance Close is the only way to suppress this dialog.

The notify event for Application Instance Close is the only way to guarantee that this VI will get a chance to shut down cleanly, because it is the only part of the VI guaranteed to run before LabVIEW aborts its execution.

For normal VIs, you would not (and should not) suppress the "abort running VIs?" prompt, because you will want the user to shut down your VIs from their panels.

Thanks for the comments!
- Christina

PS Sorry for the lapse in posts. November was National Novel Writing Month, so I was short on spare time. :-)

11:30 AM, December 14, 2007  
Anonymous Henrik Skupin said...

That's true. For this case it's really smart. Thank you for sharing this idea! I think that I could use this topic for a demonstration in one of our next user group meetings next year.

8:03 AM, December 17, 2007  

Post a Comment

<< Home