Forum > Linux
At power down ?
LeP:
--- Quote from: Thaddy on September 12, 2025, 03:17:20 pm ---
--- Quote from: LeP on September 12, 2025, 02:51:09 pm ---Additional remarks may be helpful for Windows users: in the QueryEndSession procedure it is recommended not to perform any cleanup operations.
--- End quote ---
That I do not understand. Do you have more info on that? From MS itself, not from some forum/?
--- End quote ---
https://learn.microsoft.com/en-us/windows/win32/shutdown/wm-queryendsession
--- Quote ---When an application returns TRUE for this message, it receives the WM_ENDSESSION message, regardless of how the other applications respond to the WM_QUERYENDSESSION message. Each application should return TRUE or FALSE immediately upon receiving this message, and defer any cleanup operations until it receives the WM_ENDSESSION message.
--- End quote ---
Thaddy:
No, you totally misunderstand that:
defer means it should call a clean-up, which by implication also means it can done in-place as I already thought.
There's no point leaving the procedure unless for any clean-up call.
E.g. calling free on a log is deferring, as are waitfor/free's on threads.
Or calling free on classes that is also defer in this context.
A better way to express it is like this: do not create something new inside the function, like a showmessage dialog, call the clean-up's and nothing more.
LeP:
Uhmm .... I'm not convince about you explanation.
The sequence are clear and the words too.
ONE SHOULD WAIT WM_ENDSESSION message before start a cleanup, but sure not in the WM_QUERYENDSESSION elaboration.
In the WM_QUERYENDSESSION you must respond as quickly as you can and don't do cleanup.
I never wait WM_ENDSESSION, 'cause it take preciuos time for cleanup process (I have sometimes more then 30 seconds).
P.S.: if you don't respond in the WM_QUERYENDSESSION within 5 seconds, the OS will kill your application, I don't think you have enough time to make a cleanup inside.
dbannon:
Five seconds sounds like it should be enough for most cleanups but I am quite sure there will be exceptions. Every (well, most) time I close Windows on my Laptop, it wants to do updates that always take a lot longer than 5 seconds, so there must be a means to extent that. WM_ENDSESSION message might well be that means ?
I'm guessing that WM_QUERYENDSESSION is captured by TApplication.QueryEndSession, looks like TApplication.OnEndSession captures WM_ENDSESSION to do that extending ?
LeP, do you use TApplication.OnEndSession or do you handle the calls your self ?
Incidentally LeP, your input is mos certainly relevant, any docs we get together must be as cross platform as possible.
Davo
EDIT : I just tested the TApplication.QueryEndSession, successfully delaying shutdown for five minutes. You could really annoy your users ...
In a command line FPC app, using FPSignal(), its 90 seconds.
Thaddy:
Although I have been using code like this for decades - in professional software with 100th of thousands of users - I have never run into a flaw.
So I think the addition is useful, but still think the way I interpret it is enough explanation.
(btw that code was written in Delphi, not Freepascal, although Freepascal compiles it nowadays)
I might add that a user interface is secondary to running a program. Delphi and Lazarus programmers often forget that:
It is the logic that performs, the GUI is ballast.
Navigation
[0] Message Index
[#] Next page
[*] Previous page