Refreshing the interface

I have two windows with a button. One of the button triggers a UrlConnection.Send and the other a URLConnection.SendSync

When the button is pressed, it’s disabled and a spinner is shown in the center. This works for the button which uses send (and waits for the content to be received) but obviously not for the SendSync(hronous) which halts everything until a response is received.

Before the SendSync is fired, the state of the button is changed but of course Xojo ignores that alltogether and the SendSync is fired without the button’s state being updated.

What is the best approach to force a proper refresh (of the GUI) before the SendSync?

SendSync is going to freeze the UI until a response is received. In most cases, I find that it’s just better to use Send.

1 Like

It is preferable to use Send as Jon mentioned. But, if you must SendSync something on Desktop, you can Thread it to release the UI.

2 Likes

Roger boys, I thank you for your feedback, appreciated. Good points, both.

I would tend to place the URLConnection.SendSync inside a Method that is called by a Timer (Single). This allows the UI to update and the URLConnection.SendSync/Send to run on the Main Thread and this Method can be called from elsewhere, if needed.

2 Likes

But no matter what you do, SendSync is going to wait for a response from the server. I don’t care if it’s in a timer, etc. About the only place where you could put it and have a long wait time and not hold up the UI is in a thread. If it’s on the main thread, it will block. But not sure if it is preemptive thread safe.

3 Likes

Partly why I believe the Event Driven Send and ContentReceived system is the best path.

However, I am guilty of needing a quick SendSync from time to time, so I wanted to share the way I knew of how to shim my quick debug code into a UI quickly (a Thread, as we agree on).

The Timer approach simply moves the synchronous, UI locking SendSync to after the UI releases the pressed state. The UI does still lock up, which is the part Threading avoids. I’m just explaining my preference here, do what works best for your situation.

2 Likes

If SendSync is done in a thread, does it actually yield (I suspect not) or does it still lock the UI?

SendSync in a thread yields, which is why its my “shim a quick test together” method. I fully recommend events if you can use them.