Xojo Events don't happen unless window is updated

I talked about this before, but I can’t find the thread, so I’ll start a new one.

I have discovered that events often don’t happen unless something is updated on a UI window on MacOS. I forgot that and I could not figure out why Events weren’t happening, until I remembered this and added some pointless text writing to the main window.

Other than writing something to the window or using DoEvents, how do I get events to fire (like xxxSocket.ContentReceived). Writing to a window isn’t helpful when the app is opening or closing and shouldn’t be necessary.

That’s right, I noticed this when trying to speed up TCPSockets. Events wouldn’t fire unless something was written to the main window.

Cant say I have ever seen such a thing like needing to update something on a window to make sure events run
they’ve not even part of a window specifically but part of the main event loop which runs regardless as long as the app is running

Lol. How soon you forget! :slight_smile: I even showed this to you when I was testing TCPSockets for speed. If I don’t write anything to the screen, the TCPSocket.DataAvailable event stops firing.

Same issue with URLSocket.ContentReceived. Doesn’t fire until something is written to the Main Window. I would assume there are other ways to get it to fire, but the only other one I’ve found is DoEvents, and we know how everyone feels about that!

You may do a timer on the window with e.g. 1 ms to call Socket.Poll

Thanks, but I was sort of thinking of a more general way to stop events from being blocked.
There’s no poll for URLConnection, for example.

Do you have an example of this happening between two xojo apps, with source code for each that you can share?

I’d have to make something to use as a demo.

It would be great if you could then we might be able to get to the bottom of the problem.

Well, it’s very difficult to reproduce with 2 Xojo apps. I can’t actually recreate the problem that way.
However, if I send data to and from TCPSockets from an external program (not Xojo) then the problem is easy to see.
The Xojo program just receives data in one socket and sends it out the other.

In this video, I start with the Xojo program merely displaying the # of bytes it receives. If the Xojo program is displaying the # of bytes (updating the UI) then the data flows fine.

Then, I turn off the displaying of the # of bytes, and after a while, the communication slows right down. Merely clicking on the Xojo window (bringing it into focus) and the data starts flowing again. Basically it seems to need SOME kind of UI interaction to keep the TCPSocket events firing.
To do a URLConnection demo, I’d have to create a web page that it sends data to and from, and that’d be a lot more work.
This demo shows the issue.

I’ll post a link to the source, but you’d need external devices sending/receiving TCP data for you to test. I’m using a digital mixer and editor which communicate via TCP.

Here’s a link to the source.

I had a bunch of stuff in there to try and get 2 Xojo programs to communicate (sending a message or a bunch of numbers from one app to the other) but that doesn’t recreate the problem. So the “Send” and “Send Numbers” and other text fields were for that.

That’s around 60 seconds, hmm before I dig out my old mac laptop or reinstall mac os in a vm (just rebuilt machine):

  1. Does it happen if the Untitled app is in the foreground?
  2. Have you checked the app nap state of the app while this happens (in activity monitor under energy)?

Good call.
It WAS AppNap in this test example that was stopping things.

However, my main software has AppNap disabled (thanks to @npalardy !) but even so, still has issues with URLConnection events not firing unless the UI is being updated.

When I get time I’ll see if I can create a test that uses URLConnection.

1 Like

Sorry late to this thread, but yeah it sounds like App Nap.

How are you triggering an App Nap assertion? There’s two main types and several different options.

Hi Sam;
I have AppNap working well in my main program. I just didn’t in this demo. @npalardy gave me a module that works perfectly to disable AppNap. He’s Da MAN!