I have a page that displays report data in a listbox, with a refresh button to update the data. It takes about 5 or 6 seconds to recalculate everything, so I wanted to have the refresh button show a WebDialog to let the user know something is actually happening, run the calcs, and then automatically close the dialog when the calcs are done.
The problem is the dialog doesn’t actually appear until after the calcs are done and then it immediately closes. Here’s the code in Button.Pressed:
ReportRunningDlg.Show
GenerateReport
ReportRunningDlg.Close
Is there a way to implement this that gets me what I want?
This is really terrible advice, but if you don’t have plans to move the code to other platforms, you could cheat and put those three lines in a WebThread.
Try calling GenerateReport in the ReportRunningDlg.shown event.
That is what i tried initially, but i get the same result as the current setup.
I have tried using a Timer.CallLater() to give the dialog time to display (and it does), but I am getting a NilObjectException in GenerateReport when I do that. GenerateReport is a series of queries against Session.DB, so I think that somehow with Timer.CallLater the Session goes out of context (or something).
i guess I’ll try implementing an actual timer next and see what happens.
There might be a better way, but this works:
- Timer on page
- Button.Pressed opens the dialog and starts the timer (single run)
- Timer.Run calls GenerateReport and then closes the dialog
The best way is to use a WebThread, as @Tim_Parnell mentioned.
In order to avoid blocking the Main Thread, the WebTimer needs to be configured to run on the Browser. Otherwise, any other request will have to wait for GenerateReport method to finish before the framework can handle them.
The problem putting some code in a Browser WebTimer is that the request could timeout if it takes too long. Even if the Run event finishes, the browser might close the connection before receiving any response.
A WebThread won’t block the Main Thread and will be able to send the response through the EventSource dedicated socket, as soon as your report finishes.
In short, anything that won’t return an immediate-ish response will be better to place it on a WebThread.
I like that better. thanks @Ricardo_Cruz !
1 Like