Threads and UI madness

The UI access from threads problem was already discussed a lot, I know, but this time I have troubles on how to find a (decently working) solution.
I’ve no problem on implementing timers, etc. for normal UI operations from threads and never been a “Xojo MUST provide a different solution” guy, but I feel sometimes things are too much complicated with the current approach and start thinking that a different solution should be offered, at least as an option.

My problem:
I have a ContainerControl with a TextArea which display (styled) text received from a socket. The text need some changes here and there, depending on user settings.
I cannot change the text before displaying it, because text sometimes come very fast from the socket and changes can be very slow.
In that case, a thread accessing the TextArea.StyledText property and make the necessary changes, would be a perfect solution.
But I can’t manipulate the UI from a thread.

Now I tried to store the TextArea.StyledText in a property and accessing it from the Thread. This is a dirty trick, since the object is always the same. And in fact it doesn’t work, even if Xojo doesn’t recognize the UI access (except for some case, and I think this is a bug).

The only other solution I found, is to duplicate the StyledText object, work from the thread on the duplicate and then swap with the TextArea one.
This is a lot of work: properties, StyleRun, etc. The worst part is, when I make modifications, I have to completely replace the TextArea.StyledText with the modified duplicate. This also has some visual implications plus the fact I have to do this swap very often, as new messages are received. OK I can do batch changes, but still looks a very bad solution to me.

How easy would be to simply access the TextArea.StyledText…
Really, here if it would be a pre-made option from Xojo I would use it.

Thoughts? Comments? Alternative solutions?

I don’t know if this is allowed but I can do it on Xojo with Windows

Window1 Add a textarea myTA

Tread1 Add a Property SomeTA As TextArea

Window1 Open event Tread1.SomeTA = myTA

[quote=18112:@Jym Morton]I don’t know if this is allowed but I can do it on Xojo with Windows

Window1 Add a textarea myTA

Tread1 Add a Property SomeTA As TextArea

Window1 Open event Tread1.SomeTA = myTA[/quote]

That’s clearly not permitted, since SomeTA will contain just a reference to myTA, and this is equivalent to access myTA directly.
Yes you can do it on Windows, but you shouldn’t.

I tried the Task example coming from Xojo and it works for my problem.
I think it’s a pity leaving the Task buried into examples.
Why Xojo can’t simply include it in Xojo to have an EasyUIThread like they made for UDPSocket? I’d bet many more people will start using it and stop complaining about the UI/Thread problem.

At one time in a beta we did have a “easy thread” class more or less.

It would do any UI updates synchronously on the main thread.
Doing this automatically made performance suck so bad that virtually every beta user said please remove it.

The other alternative is to do UI updates asynchronously - which is what the task example gives you.

The MBP plugins has some thread save classes. (also for changing UI controls). Works nice.

And it works, but why not embedding this class into Xojo?

There’s many ways to deal with updating the UI from a thread and if we build it in then it’s “the one true & only way” to do it.
That’s about the biggest disadvantage.

[quote=18739:@Norman Palardy]There’s many ways to deal with updating the UI from a thread and if we build it in then it’s “the one true & only way” to do it.
That’s about the biggest disadvantage.[/quote]

Being an example also lets people see how it works and customize it to their own needs.