Run custom code on window close

I’m using ExeOutput for PHP 1.6. My application launches several processes that run in the background. The main app makes ajax calls that last for several minutes and I’m using other ajax calls to monitor their progress. I’m also using ajax calls to terminate the long processes, should the user initiate this from the interface.

The problem is that, when I close the window from the X icon, the process hangs. The window does not close and the background processes continue to run until they end. If I end the process from the Task Manager, then the window closes.

So I’m looking for a way to:
a) either run some sort of HEScript function to “terminate” all running PHP processes
b) or run (but reliably) some ajax calls to terminate the processes myself.

I was thinking about using the window onunload javascript event and bind the ajax calls to that, but ajax calls are by default async, so calling them on a javascript event would immediately return the control to the event handler and I would have no guarantee that the ajax calls would complete. Maybe using sync ajax calls would solve the problem, but I thought I’d ask first if there isn’t any reliable way to execute code when the main window is closed.

Thanks!

Unfortunately, ExeOutput 1.6 doesn’t have the option to cancel a running PHP script. We have an HEScript event for the UserMain script that could do the job:

function OnWindowCloseQuery (WindowName: String): Boolean; When a user wants to close a window. Set Result to False if you do not want the window to close or True if the window can close. This event is not created by default. You will need to add it manually to the UserMain script of your project if you want to use it.

However, I don’t remember in which version we introduced it, so maybe it is not available in v 1.6.