LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect an external application close event?

Hello,

I have an executable running at startup (scheduled task) and always staying alive on my server. When the server is rebooted, I would like to take some actions (write in a event log, etc) before my application is closed by windows.

So how can I detect that Windows is closing and that it's time to do the associate actions before the closing.

I've tried the 'Application close event' in an event loop but doesn't seems to work.

I'm using labview 8.2 on Windows server 2003.

Thanks in advance!!

Vincent
0 Kudos
Message 1 of 15
(5,621 Views)

I believe Application Close event only fires if someone presses the "X" on the upper right to close the window.  Not sure how to grab an event on Widows closing the application.

 

Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 2 of 15
(5,617 Views)
I am working on the same problem, how to gracefully shutdown a service that was killed by the OS.

Current plan is to make the auto-launched service be just a manager for the real application.

1) when the manager service is started, have it launch the real app.
2) while service manager is running, it increments a counter
3) real app monitors counter, starts its own shutdown sequence when the counter stops or disappears

This should properly handle the situation where the OS kills the manager; don't know yet about windows shutdown.

I will probably use a shared variable for the counter, just because there are already shared variables,
but there are lots of other ways to share the counter.

I expect I will be working out code later this week or early next; I'll post back what I find.

Matt


Message Edited by Matthew Williams on 02-25-2008 09:31 AM
0 Kudos
Message 3 of 15
(5,610 Views)

I was also thinking can you register for a win32 event to capture the shut down?  I don't know how to implement but may also be an option.  Let us know how it goes.

 

Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 4 of 15
(5,606 Views)
You should use the "Application Instance Close" event instead.

Regards,

Wiebe.


0 Kudos
Message 5 of 15
(5,596 Views)
Thanks both Mattews for your post!

The problem that I see, with the service manager, is that the application might be shutted down before the service manager... In that case, the application won't see anything and the "gracefully close" won't append. Am I right assuming this?

As Matthew Fitzsimons I was thinking of a win32 event... Don't really know how to do this either, I will have to work on that.

For the 'Application Instance Close', this is what a meant in my first post. I did not work for me...

Any other elegant way to do it?

Vincent
0 Kudos
Message 6 of 15
(5,589 Views)
I tied this and it did capture the application close event.  What I did was while running LabVIEW in developer mode I used Windows Task Manager to kill the process.  It did throw an Application Close event.  I don't have time to try other cases like shutdown or what happens if it is an EXE but hope this helps.
 
Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 7 of 15
(5,574 Views)
Thanks again Matthews for your help.

I just tried the same thing but as an executable (writing in a file if an event occurs) and it didn't throw the 'application close event' when I killed the process using the task manager.
I guess the same thing appends when Windows is shutting down.

Vincent
0 Kudos
Message 8 of 15
(5,565 Views)
Do you know if it works when run in developer mode?
Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 9 of 15
(5,559 Views)

Hi Vincent,

you can use the function "GetMessageA" from the User32.dll to get specific Messages in your application. The 0x11 Message is the QueryEndSession Message which will be send if windows will shut down or reboot.

Hope this helps.

Mike



Message Edited by MikeS81 on 02-25-2008 09:33 AM
0 Kudos
Message 10 of 15
(5,557 Views)