Thread in Windows from example 14.3 Introduction

Hi guys, I’m a newby in Xojo and trying to find my way around.
Going through the examples in the Introduction manual I stumbled across something I really don’t understand. I’ve searched the forum but can’t seem to find the answer.
I followed the example “Creating a responsive interface” which has a timer and a single thread.
The code is pretty straight forward. It works fine on my Mac, but it doesn’t work on Windows…
It looks like the thread has only run once - while the code is exactly the same on the Mac.
I hope somebody can help me understand what’s happening (e.g. what the difference in the Windows environment is).

Hi Maarten. I’m sorry to say that your first foray into Xojo has highlighted a very old bug and an obviously untested example in windows. The max value for a progress bar in windows is 65535 (uint16) and the demo quickly goes over that and makes it look like the progress bar is finished after hitting 65535 when the process is actually still counting to 10’000’000 in the background which is why you then get the thread already running error after the bar gets to the end and you click the button again.

To fix the problem, you could either change the 10’000’000 to 65535 in Thread.Run and Pushbutton1.Action which will make the progress quicker or change Progress = i to Progress = i / 152.59. You’ll need to set ProgressBar1.MaximumValue = 65535 whichever method you choose or you’ll get an overflow setting that to 10’000’000 and it’ll end up as 39062 which will confuse things even more.

I can only assume this hasn’t been found already as few people will work through the introduction to programming in windows and even fewer, unlike yourself, will question why this example fails.

You could do a few tweaks and change things to work off a 0-100 scale if you wanted which is probably what most do with a progress bar which is probably another reason why this bug has not been found until now.

I’ll add this bug into the feedback system when I get a moment. Do let us know if you have any more questions, and have fun!

1 Like

Thanks Julian,
for the explanation!
I also found that the order of the statements when the maximumvalue is reached in the Timer’s Action event is crucial on WIndows. First you need to set the timer’s runmode off and then display the message, otherwise the timer gets fired again
Kind regards
Maarten Visman