Forum > Linux
At power down ?
LeP:
For those using Windows (not entirely relevant to the needs discussed here, but relevant to the topic),
I intercept the QueryEndSession message and request a time extension to perform all necessary operations, including asynchronous ones.
At the end, in the destoy procedure I release the lock and Windows shutdown or logoff the session.
This is because in Windows, the QueryEndSession message must be completed within 5 seconds, after which the operating system terminates the application.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function ShutdownBlockReasonCreate(hWnd: HWND; pwszReason: PWCHAR): BOOL; stdcall; external 'USER32.dll' name 'ShutdownBlockReasonCreate';function ShutdownBlockReasonDestroy(hWnd: HWND): BOOL; stdcall; external 'USER32.dll' name 'ShutdownBlockReasonDestroy'; procedure TForm1.FormDestroy(Sender: TObject);begin ShutdownBlockReasonDestroy(handle);end; procedure TForm1.QEndSession(var Msg: TMessage);begin ExitCode := 0; Msg.Result := 1; ShutdownBlockReasonCreate(Handle, 'Delayed'); Close;end;
Thaddy:
You are using the form's handle and that seems wrong to me.
On Windows, pass hInstance. (The application windows handle)
The reason is that the form may be destroyed while there are still running tasks associated with the application.
The global hInstance variable is associated with WinMain and is the correct handle in this particular case.
Otherwise it is a useful addition to the discussion.
One extra remark: ShutdownBlockReasonCreate() must not be called from within QueryEndSession itself, it seems you must call it before QueryEndSession is entered. I tested and put it simply in Mainform.Create;
LeP:
--- Quote from: Thaddy on September 12, 2025, 02:01:38 pm ---You are using the form's handle and that seems wrong to me.
On Windows, pass hInstance. (The application windows handle)
The global hInstance variable is associated with WinMain and is the correct handle in this particular case.
--- End quote ---
May be you are right, but I always used in this way (since times of XP) and it works. I'll do some test in the future with HINSTANCE.
--- Quote from: Thaddy on September 12, 2025, 02:01:38 pm ---The reason is that the form may be destroyed while there are still running tasks associated with the application.
--- End quote ---
It's not possible, the Main Form is always the last resource opened. I always shutdown all things waiting for all, for this I used extended procedure for shutdown.
--- Quote from: Thaddy on September 12, 2025, 02:01:38 pm ---One extra remark: ShutdownBlockReasonCreate() must not be called from within QueryEndSession itself, it seems you must call it before QueryEndSession is entered.
--- End quote ---
Yes, it's possible but there is not meaning. If the application doesn't catch QueryEndSession it means that something was wrong so it's indifferent about extended or not the "shutdown".
This procedure is connected specifically to OS operations so I prefer to do like should do.
Additional remarks may be helpful for Windows users: in the QueryEndSession procedure it is recommended not to perform any cleanup operations.
Thaddy:
--- Quote from: LeP on September 12, 2025, 02:51:09 pm ---[It's not possible, the Main Form is always the last resource opened. I always shutdown all things waiting for all, for this I used extended procedure for shutdown.
--- End quote ---
It is possible. Loads of my server applications only have a form to make some settings or to shutdown. All services/tasks run independent of the form.
Thaddy:
--- 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/?
Navigation
[0] Message Index
[#] Next page
[*] Previous page