PxPlus User Forum

Main Board => Discussions => Programming => Topic started by: davidr on February 08, 2019, 01:55:59 PM

Title: Recognizing Windows Shutdown/Logoff...
Post by: davidr on February 08, 2019, 01:55:59 PM
I'm trying to figure out if there is a way for my Providex program to recognize a shutdown (or logoff) from the Windows system.  I did some research and found references to the System.Environment.HasShutdownStarted variable and SystemEvents.SessionEnding event within Windows, but I'm not sure how I would access either of these in Providex.  I also looked at the Event directive in the manual, but I don't believe this will capture a Windows shutdown.

Essentially I want to be able to gracefully close my Providex program when a Windows shutdown is detected in order to prevent any data loss or corruption.

Any insight is greatly appreciated.

Thanks.
Title: Re: Recognizing Windows Shutdown/Logoff...
Post by: Stéphane Devouard on February 11, 2019, 10:26:31 AM
David

When Windows shuts down or a session logs off, it sends a message to the main window of all running processes to ask them to close.
I think this is interpreted by PxPlus as a CTL = -1999 which is mapped to CTL=4 (see the *dev/windows driver)
So if your programs are written in such a way that they are regularly checking the input queue or are idle waiting for a CTL event (which would be the case most of the time with Nomads or iNomads based apps) and if they are processing either of those CTL values as if an end-user had closed your app, then you should be OK.

Hope this helps
Title: Re: Recognizing Windows Shutdown/Logoff...
Post by: davidr on February 12, 2019, 09:24:13 AM
Stéphane,

I hadn't looked at the CTL values.  I tried to capture the -1999 and 4 CTL values in the Nomads User Defined CTL Values.  Unfortunately neither one appears to be triggered on a Windows logoff/shutdown.  I looked through the rest of the CTL values, but didn't see anything that indicates a shutdown value.  My guess is that only someone at PVXPlus can answer this question unless someone else has already accomplished this.

Thanks.
Title: Re: Recognizing Windows Shutdown/Logoff...
Post by: Stéphane Devouard on February 13, 2019, 09:07:00 AM
David,

If you look at the *plus/winutl/service program which is the PxPlus INITTAB emulator for Windows, once it has launched the configured programs and while it is monitoring them, it also uses the following code to scan the input queue, and should it receive a CTL 4 or -1999, it breaks from its pooling loop, stops the launched processes and dies :

Code: [Select]
0113 IF UNIX THEN WAIT 5 ELSE OBTAIN (0,TIM=5,ERR=*NEXT)'BI',*,'EI'; IF CTL=4 O
0113:R CTL=-1999 THEN LET L$="Close CTL ("+STR(CTL)+") received"; GOSUB LOG_EVE
0113:NT; BREAK

I would think that Windows sends the same type of message when shutting down or closing a user session than when stopping a service. But I may be wrong ;)
Title: Re: Recognizing Windows Shutdown/Logoff...
Post by: davidr on February 15, 2019, 08:36:54 AM
Stéphane,

That looks like what I may be looking for; however, I'm using Nomads, so I don't know how I would do an obtain (or capture the CTL) within this framework.  As I said I tried to capture the values in User Defined CTL Values screen in Nomads and set the action to End, but nothing happens when I log out.  Windows also provides a prompt saying that some tasks are still running.

I also wonder if doing my own obtain would interfere with anything Nomads is doing.

I feel like we are close to figuring this out, so thanks for your continued input.