jdunham Posted January 10, 2012 Report Share Posted January 10, 2012 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: http://forums.lavag.org/WM-QUERYENDSESSION-t1285.html 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? Quote Link to comment
ned Posted January 10, 2012 Report Share Posted January 10, 2012 The Windows Message Queue library lets you catch and handle Windows events, but I don't know which one you'll need to check to determine if your application should shut down. I have used this library to receive Windows messages from another application. Quote Link to comment
asbo Posted January 10, 2012 Report Share Posted January 10, 2012 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. Quote Link to comment
Saverio Posted January 10, 2012 Report Share Posted January 10, 2012 This page contains the various messages: http://msdn.microsoft.com/en-us/library/windows/desktop/ff468922?v=VS.85%29.aspx. The individual pages provide the hex values for the messages. Quote Link to comment
jdunham Posted January 11, 2012 Author Report Share Posted January 11, 2012 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. Quote Link to comment
Ton Plomp Posted January 11, 2012 Report Share Posted January 11, 2012 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. Ton 1 Quote Link to comment
jdunham Posted January 11, 2012 Author Report Share Posted January 11, 2012 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. Quote Link to comment
code ferret Posted February 14, 2012 Report Share Posted February 14, 2012 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. Quote Link to comment
Wiebe@CARYA Posted December 16, 2014 Report Share Posted December 16, 2014 Hi, 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... Regards, Wiebe. Quote Link to comment
Phillip Brooks Posted December 17, 2014 Report Share Posted December 17, 2014 (edited) 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 December 18, 2014 by Phillip Brooks Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.