ThreadAccessingUIException on Xojo Build - Not RS Build

I had a previous app made with RS and tested this on Windows XP Pro via VirtualBox. The exe worked fine aside from a focus issue I still needed to fix.

I compiled the same app with Xojo for Windows and dragged the compiled folder into the shared folder used by VirtualBox. The folder contains the exe file, a folder for the libs, and four text files I’ve added. A installer was not used.

When I start the app I am getting a ThreadAccessingUIException message, which i see has to do with threads.

The open event of my App runs a thread which opens the four text files and assigns the data they contain to five app properties (4 strings and 1 dictionary).

This is an indication that a thread in your application is attempting to directly modify a UI component (textbox, label, etc.). This is no longer allowed. You need to look through your source code again and check for this.

[quote=149521:@art ouette]I had a previous app made with RS and tested this on Windows XP Pro via VirtualBox. The exe worked fine aside from a focus issue I still needed to fix.

I compiled the same app with Xojo for Windows and dragged the compiled folder into the shared folder used by VirtualBox. The folder contains the exe file, a folder for the libs, and four text files I’ve added. A installer was not used.

When I start the app I am getting a ThreadAccessingUIException message, which i see has to do with threads.

The open event of my App runs a thread which opens the four text files and assigns the data they contain to five app properties (4 strings and 1 dictionary).[/quote]

Things have changed since the RS days. The latest versions of Windows and Mac OS X require that threads do not read or modify anything in the UI. So something as simple as looking at a TextField.Text property cannot be done directly. The simplest way to proceed is to use a timer to do so. Search the forum with ThreadAccessingUIException and you will find a couple hundred posts about that, together with examples.

I disabled three threads within the main window which would not actually be running at the launch of the application - you’d need to actually use controls in the main window to run these threads. I left a thread located outside the main menu intact, but still get this error on the Windows build upon launch even though the thread does not access or change any controls in the main window.

The open event event for the app runs a thread not found in the main window. This thread opens four text files stored in the same folder as the application and assigns the resulting strings from the files to app properties (i.e., app.mystring). No controls in the main window are changed or referred to and it does not alter any other main window properties such as strings (i.e., window1.mystring).

So this restriction on threads also applies to the app object?

[quote=149590:@art ouette]I disabled three threads within the main window which would not actually be running at the launch of the application - you’d need to actually use controls in the main window to run these threads. I left a thread located outside the main menu intact, but still get this error on the Windows build upon launch even though the thread does not access or change any controls in the main window.

The open event event for the app runs a thread not found in the main window. This thread opens four text files stored in the same folder as the application and assigns the resulting strings from the files to app properties (i.e., app.mystring). No controls in the main window are changed or referred to and it does not alter any other main window properties such as strings (i.e., window1.mystring).

So this restriction on threads also applies to the app object?[/quote]

I quickly tested setting a app property from a thread, no problem.

Can you simply comment out all Thread.Run in the program and see if the error still manifests ? It had to be in the remaining thread…

I found the error in the thread. It appears to be a MsgBox line buried in the code.

The other three threads in the main window will need some further thought as they are used to run regex searches with the thread updating listboxes in the main window with the results of the search.