LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Differentiate between user and windows triggering Panel Close? event

Solved!
Go to solution

Hello,

 

I have a rather large application which is launched at windows startup and now also supposed to shutdown cleanly at windows shutdown.

 

From some initial tests, I figured the "Panel Close?" event is triggered at windows shutdown (and for testing purposes also when ending the task via TaskMgr "End Task").

From documentation it sounded like the "Application Close?" event should ideally be used, but I could not get that one to trigger whatsoever.

 

Until now the "Panel Close?" event is already used for the case when the user presses the top-right X, in which case my application checks internally if app shutdown is allowed and proceeds accordingly either with shutting down or displaying a dialog that shutdown is currently not allowed.

However during windows shutdown obviously there is no other option than to proceed with the app shutdown - so essentially the steps to be executed are different from when the user triggers the "Panel Close?" event.

 

Now my question is how can I differentiate the two cases in my code?

Are there different events which only trigger in one of the two cases? Or can I somehow differentiate within the "Panel Close?" event case, what exactly the root cause for the event was?

 

Thanks.

Stefan

0 Kudos
Message 1 of 8
(259 Views)

Hello Stefan,

 

may 'Type' and/or 'Source' give back some usefull information?

Write the to a log file and try it.

 

Timo

0 Kudos
Message 2 of 8
(250 Views)

Hello Timo,

 

thanks for the fast reply.

 

Unfortunately, the values for both parameters are the same in both cases:

Source = LabVIEW UI and Type = Panel Close?

 

Stefan

0 Kudos
Message 3 of 8
(178 Views)

Hello Timo,

 

thanks for the fast reply.

 

Unfortunately, these parameters are the same in both cases:

Source = LabVIEW UI and Type= Panel Close?

 

Stefan

0 Kudos
Message 4 of 8
(218 Views)

@kghzvi wrote:

Hello,

 

I have a rather large application which is launched at windows startup and now also supposed to shutdown cleanly at windows shutdown.

 

From some initial tests, I figured the "Panel Close?" event is triggered at windows shutdown (and for testing purposes also when ending the task via TaskMgr "End Task").

From documentation it sounded like the "Application Close?" event should ideally be used, but I could not get that one to trigger whatsoever.

 

Until now the "Panel Close?" event is already used for the case when the user presses the top-right X, in which case my application checks internally if app shutdown is allowed and proceeds accordingly either with shutting down or displaying a dialog that shutdown is currently not allowed.

However during windows shutdown obviously there is no other option than to proceed with the app shutdown - so essentially the steps to be executed are different from when the user triggers the "Panel Close?" event.

 

Now my question is how can I differentiate the two cases in my code?

Are there different events which only trigger in one of the two cases? Or can I somehow differentiate within the "Panel Close?" event case, what exactly the root cause for the event was?

 

Thanks.

Stefan


I think this is how the Windows API works.  Probably rolfk will have a better explanation than that.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 5 of 8
(195 Views)

Add a dedicated Close button and don't allow the user to close the application clicking the X in the title bar.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019
0 Kudos
Message 6 of 8
(138 Views)
Solution
Accepted by topic author kghzvi

I have used the Application:Close? filter event in the past for service like applications that do not have any visible user interface and that worked fine. What might not work well is if you forcefully quit the application, like the Force Quit in Task Manager. But then you shouldn't get a Panel Close event either. Windows simply yanks out the process from memory and cleans up whatever resources it knows about that the process has opened. That includes window, event, and file handles and the like that are managed by the kernel. Other private resources such as DAQ devices etc. it may not be able to associate with the killed process and hence it won't clean them up.

 

The Panel Close (?) event is what it says. It is triggered (before for the ? filter event, and after for the normal event) the panel is getting closed. If that is due to the application receiving a WM_QUIT message and LabVIEW sending all its windows a close event, or from a user clicking on the X button in the upper right corner, doesn't matter and can't be distinguished when receiving the event.\

 

Intercepting the Panel Close (?) event isn't necessarily sufficient to detect that LabVIEW is going out of memory. A LabVIEW VI can very well be non-open (which is distinctively different from being hidden) and still running as long as there is at least one reference to the VI open. There are implicit references such as when a VI is used as subVI, but it can be also an explicit reference, for instance by explicitly opening a VI reference to itself when starting up the VI. This way a VI can very well stay in memory even if it is top level and its front panel closed, since the reference keeps it alive.

Once all references to a top level VI are closed and there is no front panel to it open anymore, the VI immediately is terminated no matter if it is in the middle of a running loop or whatever. Once the last top level VI goes out of memory the LabVIEW runtime also automatically will quit itself when it is running as built application.

Rolf Kalbermatter
Averna BV
Message 7 of 8
(122 Views)

Hello and thanks for your support,

 

the issue was in fact with the way I was trying to simulate the windows shutdown.

Apparently the articles I found on other websites were incorrect, as Rolf explained ending a task via Task Manager is not the same than what happens during windows shutdown.

For clarification: My application is expected to always have its front panel open since it is in fact a Teststand user interface. When I open the task manager, select my application in the process tab and press the "End Task" button ("Task beenden" in German), my application does receive the Panel Close? event. However even though I discard that event in the event case, the application is gone immediately after.

 

Registering for the Application Close? event was the solution after all. Though one has to pay attention to finish the shutdown of the application before the windows timeouts kick in, or increase the timeouts in the registry.

 

For other users looking to debug that topic:
There is a Microsoft Tool called "Restart Manager", which can be used to simulate a windows shutdown for a specific process only. The tool is part of a bundle called "Logo Testing Tools for Windows". Though a download link for that bundle is hard to find since Microsoft apparently stopped distributing the tool.

 

Stefan

0 Kudos
Message 8 of 8
(111 Views)