When the TCP socket is receiving data, it blocks the execution of the Timer Action

Here is the scenario:

  • I have a socket server that instantiates up to 40 TCPSockets.
  • I have a timer (Timer1) with run mode set to “multiple” and period set to 1 second (1000).

When the 40 TCPSockets are receiving data, the timer is ignored, even though it is supposed to trigger every second.

If I disconnect all the TCPSockets, the timer starts working again;
has anyone encountered something similar?

W11 Pro, Xojo 2026R2 (67638)

basicaly you can say if xojo is inside of a method in blocks the main loop from continue.

I logged this enhancement to improve TCP sockets:

https://tracker.xojo.com/xojoinc/xojo/-/issues/81087

1 Like

I don’t quite follow: are you saying that if one of the TCP sockets is receiving data—triggering the dataAvailable event—it won’t process any other code until that execution finishes?
So, would 40 TCP sockets receiving data continuously block all other application activity, including timers?

Unfortunately, the socket and timer events are all running on the main thread which means only one method can run at a time.

You need to make the DataAvailable events do as little as possible - ie: add the incoming data to a buffer and process it via a thread.

The enhancement which I referred to in my previous post is for sockets to use preemptive threads which would free the main thread to allow the timer to operate correctly.

1 Like

you could also run a thread and compare a datetime and then do what you need to do.
and with Preemptive Threads it could run at different cpu core too.

the question is what is your timer intent to do.

Thank you all.

i think is that the best approach is create 2 apps, one for listeners and other to elaborate buffer (Buffer = same local sqllite db for listener app end for queque elaborator app ) , the second app (queque elaborator) in not impatted from the tcpsocket of the firs app and can use premptive threads and his timer

DataAvailable will be fired on the main thread, so reading the data might block it.

Have you tried using a Thread for reading the data? Once DataAvailable fires, start the thread and read from the socket.