Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ON SHUTDOWN kinda works, but... 1

Status
Not open for further replies.

vernpace

Programmer
Feb 22, 2015
209
US
Hi All,

We have a background EXE that sends short messages via WinSock to clients over the Internet. For each client there is a connect then a send. The whole thing takes around 10 seconds for all clients. Testing shows that ON SHUTDOWN <someProc> works for only a brief period. If the computer shuts down, we need to send messages to all clients, but <someProc> does not finish executing.

Any ideas? Is there an alternative? Some ShutDown listener Win API maybe (I cannot find yet)?

Thanks,

Vern
 
Testing shows that ON SHUTDOWN <someProc> works for only a brief period.

Can you elaborate a little bit? The usual complaint is that someone can't get rid of ON SHUTDOWN.

Note that usual and normal processing during ON SHUTDOWN is to turn off ON SHUTDOWN, so if you've done that you may be shooting yourself in the foot.

Are you doing something asynchronous where VFP won't wait until it's finished while it goes about shutting down?

There's a lot of vague here. NEED INPUT! (Number Five Alive!)
 
Yes, with a server shutdown you are only informed via the on shutdown event, windows doesn't wait for your code to finish.
You also can't signal windows to wait.

If you're doing a planned shutdown you would need to trigger whatever may take longer than a few seconds before you start the planned shutdown. If it's an unplanned shutdown, eg via UPS (uninterrupted power supply), that actually can also be programmed to do such things before doing a shutdown. The period you have with the battery power is for that graceful shutdown.

But overall this is something you can't address in an application, that has to be addressed on the OS level.

Bye, Olaf.

 
Hi vernpace,

You can force Windows to abort or to delay a system shutdown - take a look at the System Shutdown Functions:



1) To abort a system shutdown, put this in Your <someProc> (called ON SHUTDOWN):

- AbortSystemShutdown
- Your code: send messages


2) To delay a system shutdown, put this in Your <someProc> (called ON SHUTDOWN):

- ShutdownBlockReasonCreate
- Your code: send messages
- ShutdownBlockReasonDestroy

Regards, Stefan
 
Thanks, Stefan, I should have looked up, if there are API calls like that instead of just saying "You also can't signal windows to wait.".

I notice one thing: There seems to only be one reason string for all windows, not for each application. So perhaps ShutdownBlockReasonQuery should be called to see whether any application already has created another reason. Anyway, I'd prefer 2.

And overall this seems to be a server running there in general available to clients. It should rather run 24/7 and restart right away. There's even a DOS command doing that, which I introduced one or two years ago in some internal application update needing a restart after having updated a windows service.

Bye, Olaf.
 
Hi Olaf,

the reason string is a per application string, each application can call ShutdownBlockReasonCreate with its own reason string.

Windows will show all in a list:

- App1 icon App1 name
- App1 reason string

- App2 icon App2 name
- App2 reason string

- and so on ...

So there's no must to call ShutdownBlockReasonQuery before - you can but you have not ;-)

Regards, Stefan
 
OK, good to know.

And as I said there even is a DOS command to make such a shutdown with restart:

shutdown /r /t 15 /c "Restart is needed after a new installation"

For example restarts after a 15 seconds wait period with restart (/r) and the comment (/c) "Restart is needed after a new installation".
So if you don't only need to reacting to but even initiate a shutdown you can do this, of course after sending messages.
Same applies to using the InitiateSystemShutdown or InitiateSystemShutdownEx API calls, of course.

Bye, Olaf.
 
Stefan,

This is EXACTLY what I was looking for (approach #2). The APIs are simple, no need to create structs. If this works, then I can make the background EXE a Win service.

Mucho Danke,

Vern
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top