Jump to content

Catching Windows AppClose events

Recommended Posts

I'm trying to catch the external application close event and shut down cleanly.

This forum post on the dark side links to an old LAVA thread:


but in the new world order, that link no longer works.

But I care more about the right answer than the link. Can I catch the an OS-initiated application close/shutdown message from inside of labview?

Link to comment

If I recall, you'll want to watch for at least the WM_CLOSE event, but there are a couple other system-level ones (WM_SHUTDOWN?) that might be prudent as well. MSDN has good documentation on this... somewhere.

Here's the post that link was referencing: http://lavag.org/top...ueryendsession/. Keep in mind that WM_QUERYENDSESSION is *only* for system shutdowns, which is one of several ways an application can be asked to terminate.

Link to comment

Thanks for the replies. I checked out the Windows Message Queue example (thanks, ned) and it works fine. In my case, we are our LabVIEW executable as a service (with FireDaemon), and I think it will be enough to monitor the Application Instance Close? event and filter it and then do a graceful shutdown.

Link to comment

Yep, the Instance close? filter event is the right one.

If you don't close withing N seconds, the user will be shown a 'This app is not responding, end now?' function.

What was the reason you didn't directly looked for this event?

For future references, here's a snippet of the event.



  • Like 1
Link to comment

Yep, the Instance close? filter event is the right one.

If you don't close withing N seconds, the user will be shown a 'This app is not responding, end now?' function.

What was the reason you didn't directly looked for this event?

I knew about the event, but I wasn't sure it would process Windows messages generated from outside of LabVIEW. I ended up building a test anyway to make sure that it still worked as claimed when running as a service.

But since I Googled something like "labview application close external event", and got very little useful information (and nothing dated later than 2008), I figured a Lava post was in order, and it was certainly helpful.

Link to comment
  • 1 month later...

One nice side effect of handling the "Instance close" event is that it provides a nice way to close certain types of aplications which are otherwise awkward. For instance, if you are working with a VI that has no title bar (for an embedded or kiosk UI application, for instance), but it also has no exit button or other UI control for exiting, how can you gracefully shut it down while working with it in development? There are any number of ways, but handling the "instance close" event provides a convenient way. Assuming you are using a project, you can close your VI by clicking on the LV project viewer's title bar close button (the "'X' in the upper right-hand corner) and it will close your VI, but not LV or the project viewer. Of course, if you build your VI into an executable, if you use the windows task manager "applications" tab to kill the VI, it will be handled "gracefully" as well.

Link to comment
  • 2 years later...



Has anyone tried this on Windows 8? I'm testing a LV11 application on Windows 8.


It seems WIndows 8 does trigger "Application Instance Close?" in a normal exe when Windows shutsdown. But the Disgard flag seems to be ignored. Meaning that only the code inside the event seems to be executed, and nothing else. This might be a timing issue, although I'd expect the kill after seconds, and the exe shuts down in a flash.


With  the app running as a service (created with task scheduler), the event is not triggered at all when windows shutsdown. It's almost like Windows tries to send a WM_CLOSE (as documented), but the service has no window, so it kills the service (as documented). The same happens when you use task scheduler to end the task manually...


When task manager is used to end a normal exe, Windows Vista triggers the event, but windows 8 does not...





Link to comment

LV2011 is not listed as supported with Windows 8.


I know that doesn't mean the code won't run, but the behavior sounds similar to a problem I saw when trying to run LV 8.6 on Windows 7.


Specifically, I had UI code that responded to various events that worked fine under XP, but locked up my app under Windows 7. I think one of the events was "Application Instance Close?"


This specific event might be used as an exploit by some viruses to force the close of antivirus software. Windows changes the interface and your 'unsupported' version of LabVIEW fails the OS call.

Edited by Phillip Brooks
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.