Yeah thats the correct.
QueryEndSession - Asks apps if they can shutdown.
If any apps Return False (No), then the shutdown process is generally aborted except Forced Shutdowns.
If all Return True (Yes), then EndSession is sent out and Windows Shutdown proceeds.
EndSession - there should be a period of time for the app to shutdown BUT the OS can kill any and all processes if its wants.
What I’m seeing is there is no default 20 second wait for the App.
There is a HKCU App timeout setting, mentioned here.
The reg setting can be found in XP as well, and exists on my (virtual) machines.
HKEY_CURRENT_USER\Control Panel\Desktop
WaitToKillAppTimeout = “20000”
There is also a regsetting to prevent auto termination of apps, which does not look like it might apply to the shutdown process, because mine is set to zero and apps still get auto terminated.
HKEY_CURRENT_USER\Control Panel\Desktop
AutoEndTasks = “0” ; prevents forced termination
So I’m stuck in a situation where the app seems to be killed prematurely by windows after WM_EndSession and there’s nothing I can do about it.
If I shutdown on WM_QueryEndSession, which will save all data down cleanly but this goes against what Raymond Chen is suggesting, plus there is also the risk the Shutdown process is aborted and thats when I still want my app to be working.
Chen does state
In practice, displaying a prompt is usually not a good idea because if you don’t respond to the message after a few seconds, the system will shut down without you.
I’m not displaying anything, but earlier on in the post he mentions starting a background thread to perform the data save.
When you get the WM_ENDSESSION message, you wait until that background operation completes before telling the system, “I’m good; you can shut down now.”
Here he’s suggested waiting in a subclassed procedure before Returning True or False.
Problem is, these windows are paused and thus cant save any data because these are subclassed procedures, and Chen should know this. The only things accessible to them is global data and global functions, unless this is a Clarion issue?
I note the Clarion Frame Extension class sends a Notify from the subclassed procedure, if using the systray template, which puts a msg in the msg queue, but there’s no chance of being able to save the data on WM_EndSession using this template & class, because the windows are paused.
from WinExt.clw
OF WM_QUERYENDSESSION
IF GloCurrentWinExt.AllowShutDown
GloCurrentWinExt.OnShutDown=GloCurrentWinExt.ProcessShutDown()
IF GloCurrentWinExt.OnShutDown
RETURN(GloCurrentWinExt.OnShutDown)
ELSE
RETURN(False)
END
!ELSE
! RETURN(False)
END
OF WM_ENDSESSION
IF GloCurrentWinExt.AllowShutDown
NOTIFY(Event:CloseDown,THREAD())
RETURN(True)
!ELSE
! RETURN(False)
END
So apart from storing everything in Globals which then brings back object synchronisation issues and random thread locking, I’m out of ideas.
A Loop Sleep(10) before the WM_EndSession Return T/F doesnt work either.
OF WM_EndSession
Loop
IF Condition
Sleep(10)
Else
Break
End
End
Return True