weird
in CloseQuery method you have a CanClose boolean, it's default value is True
so the Close should be called.
Try to see if CanClose is true or false.
But as Vincent said, we need to use Application.OnQueryEndSession and Application.OnEndSession.
In my opinion, there is something missing. Application QueryEndSession and EndSession should call the main form Close events, whatever if the user or the system closes the application.
But at least we have a way to make it work ^^