Modifying StyledText hangs on Windows

I have a TextArea where I am doing some syntax coloring via StyledText. It all works quickly and without issue on MacOS, but when I run it Windows it hangs on the first attempt to modify the StyledText. Here’s the first few lines where I modify it:

sTxt.FontName(0, Txt.Length) = Theme.FontName
sTxt.Size(0, Txt.Length) = Theme.FontSize
sTxt.Bold(0, Txt.Length) = False
sTxt.Italic(0, Txt.Length) = False
sTxt.TextColor(0, Txt.Length) = Theme.ColorDelimiters

I have commented out these line sequentially and it will always hang on the first one executed. This code is in a thread, and when it hangs i can’t even get the debugger to pause or stop. I can quit the app using the window’s close button, but only after Windows says the app is unresponsive and i tell it to force quit.

The text being processed is only 30 or 40 characters, so I don’t think that is the issue.

Windows 11 running in a Parallels VM on MacOS 13

You could be running afoul of the threads accessing UI rule that wasn’t fully accounted for by Xojo. Have you tried without the thread?

I had it in the main thread initially, but longer strings can take some time to process and the app beachballs on those so I moved it to a thread. I never tested on Windows until I was done with the app, so I’ll give the main thread a shot and see what happens.

It seems like you’re right @Greg_O. On Windows the code runs in the main thread, but the UX is miserable (watching the TextArea flash for 6 or 7 seconds).

I hope the bug isn’t that I can manipulate the styledText from a thread on MacOS at all, since that works great for me.

Would it be possible to, in a thread, instantiate a new StyledText object, modify it, and then assign it back to the TextArea?

I honestly don’t know. You could however, use a method that calls a thread which calls back to a method on Mac and just skip the thread and directly call it on Windows. I seem to remember there being a command on windows that lets you freeze drawing… maybe in the “I wish I knew” book about windows declares.