Understanding threading

I am beginning to build a Cloud Sync feature into my application. The application is a two part (desktop/webapp) system. Files are stored locally. I will be adding a feature to have all the files synced with my server for cloud access and resyncing with other computers.

However, I am struggling with the spinning beachball or hourglass (depending on OS) when running communication, uploads, and downloads with my web app. I am using threads and timers is the best way I can read about in the documentation and examples. But my desktop app is still locked up while working with the web app. The Windows experience is far worse - causing the app to appear crashed in the “not responding” state.

My request is a resource for learning about threading. I was under the impression that when you fire off a thread, the UI should be fulling responsive. Then use a timer to update a status in the UI so the user knows what’s up. But my experience has been that using a thread still locks up the app. And my timer isn’t helping. I but a break in the timer’s action event, and it never breaks. The timer is set to default 1000 and is started.


That your timer is not hitting its break statement is an issue
How do you set things up ?
I assume in your threads Run event you have something like

myTimer = New Timer
// my timer is a property on this thread subclass
addhandler myTimer.Action, addressof methodToHandleTimerAction
// methodToHandleTimerAction is a method on my thread subclass
// that is declared like methodToHandleTimerAction(whichTimer as Timer)

myTimer.Period = 1000
myTimer.Mode = TImer.ModeMultiple

// now the rest of the code for my thread & whatever it does

the reason to set it up this way is then the timer has full access to all the properties on your thread subclass

I have added a timer to my window in the canvas. Then added an action event that updates the UI with property values of the “download thread”.

Then a button in the window has an action event that checks if the thread is already running. If not, it begins the timer and then runs the thread.
I added a msgbox to the timer event to check, and it never shows… just the spinning beachball for ever. I know the thread runs. I have the web app running in debug mode on my same computer. I can break inside the HandleSpecialURL and see it generate the requested data and request.print it back. But the desktop app never updates.

However, from your code… you added a timer object in the thread’s run event?

If a thread calls some blocking action, the entire app is blocked. What is your thread doing? And if you’re updating the cloud, couldn’t you use an asynchronous socket instead of a thread?

And stupid question: How do you start the thread? Ie., are you sure your code is running in a separate thread and not the main UI thread?

I think there is a Task example in Xojo Examples folder. I would anyhow use better a notification OOP pattern if time is not critical. There is an excellent xDev magazine article by @Sam Rowlands about it.

A synchronous HTTP transfer would do a beachball.

Too much code in a timer as well.

@Tim Hare I’ll check into a socket. The thread is started from a button click event.

@Amando Blasco Thanks for the tip. I’ll check that too. How does a Task differ from other implementation?

I am thinking I may need to cut down the data being transferred into smaller parts and somehow have the desktop app time to process and then get more data or something… hm…