Hi, I’m using a command from MBS to calculateDirectorySize in a thread, but I always get a warning in my app that this is not legal to alter the main interface from a thread but where do I alter it ? here is my threadcode in the run.
Dim f2 as folderItem
f2 = app.gDragger.FolderItem // app.gDragger is a global property of a dragitem which is a folderItem, tried to move it to app, but no help.
dim d as DirectorySizeMBS
d = f2.CalculateDirectorySizeMBS(True,0)
app. gSizeNo = d.LogicalTotalSize/1000000000
So now I run a timer to check if the thread is done, and that one is supposed to check the gSizeNo (a global property) .
I suggest you to move this question from General to Add-Ons, and change the topic to “CalculateDirectorySizeMBS on thread problem” so it can call the attention of MBS (Christian) more easily.
As of Xojo 2013r1 (I think) accessing the GUI from within the context of a thread will raise an exception.
Your solution using a timer will work, and using timers triggered by threads is the recommended way for threads to modify the GUI. It’s always safe to access the GUI in the Action event of any timer.
But, both of these are at app level and not at window1 level. So not in the mainGUI ?
I can’t see how this code is trying to manipulate UI element .[/quote]
Accessing a DragItem from a thread will raise a ThreadAccessingUIException. While only a Xojo engineer can say for certain, I’d conjecture that the DragItem class is explicitly checking whether it’s running on the main/GUI thread and raising an exception if not.
Thanks Andrew, that solved it. Now I just used a string for nativepath, and lower the ticks in the MBS command to 3. Now it worked.
Now I can even run sliders up and down, while the command is calculating all foldersizes on my disc.