Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Nov 16, 2019 7:01 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Progressbar won't update
PostPosted: Thu Sep 06, 2012 10:33 am 
Offline

Joined: Fri Dec 09, 2005 6:25 pm
Posts: 357
I have a progress bar that is supposed to update each time a file is processed. It works on the Mac, but the same code does not work on Windows...
for z = 0 to ubound(itemArray)
j = 0
f = getFolderItem(itemArray(z))
fileName = f.name
ProgressBar1.visible = true
ProgressText.text = "Reading File: " + f.Name
ProgressText.visible = true
ProgressBar1.value = 0
progressBar1.maximum = 65536

ProgressBar1.value = (z/ubound(itemArray))*65536
ProgressBar1.refresh


Top
 Profile  
Reply with quote  
 Post subject: Re: Progressbar won't update
PostPosted: Thu Sep 06, 2012 10:37 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
this won't necessarily solve your problem.... but it will ease up on a ton of internal events on the progress bar

ProgressText.visible = true
ProgressBar1.value = 0
progressBar1.maximum = ubound(itemArray)
ProgressBar1.visible = true
for z = 0 to ubound(itemArray)
j = 0
f = getFolderItem(itemArray(z))
fileName = f.name
ProgressText.text = "Reading File: " + f.Name
ProgressBar1.value = z
ProgressBar1.refresh

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Progressbar won't update
PostPosted: Thu Sep 06, 2012 10:41 am 
Offline

Joined: Fri Dec 09, 2005 6:25 pm
Posts: 357
ah yes. so obvious. I will make that change even if it doesn't solve the problem. thanks!


Top
 Profile  
Reply with quote  
 Post subject: Re: Progressbar won't update
PostPosted: Thu Sep 06, 2012 10:49 am 
Offline

Joined: Wed May 20, 2009 11:02 am
Posts: 423
Updating the UI from the main thread is considered bad practice, and cause of problems like the one you are asking about.

If that's what you are doing, check this: http://www.realsoftwareblog.com/2012/05/doing-progress-right.html

Pixe

_________________
Using RS2011r4.3 on Windows7.


Top
 Profile  
Reply with quote  
 Post subject: Re: Progressbar won't update
PostPosted: Fri Sep 07, 2012 11:39 am 
Offline

Joined: Fri Dec 09, 2005 6:25 pm
Posts: 357
I tried doing the thread thing, but it didn't help. Out of frustration I drew 2 rectangles, one on top of the other (red over white) and made my own progress bar by adjusting the width of the red one. It works great, but I have some status text above it that should update and it seems to disappear along with a couple buttons that are above it as well. I tried refreshing the window, but they still get hidden for some reason. The rectangles in no way overlap these interface elements. Why do they disappear?


Top
 Profile  
Reply with quote  
 Post subject: Re: Progressbar won't update
PostPosted: Fri Sep 07, 2012 5:18 pm 
Offline

Joined: Wed May 20, 2009 11:02 am
Posts: 423
pbesong wrote:
I tried doing the thread thing, but it didn't help.
And you used a timer too?

_________________
Using RS2011r4.3 on Windows7.


Top
 Profile  
Reply with quote  
 Post subject: Re: Progressbar won't update
PostPosted: Fri Sep 07, 2012 6:14 pm 
Offline

Joined: Fri Dec 09, 2005 6:25 pm
Posts: 357
yes, i did use a timer.


Top
 Profile  
Reply with quote  
 Post subject: Re: Progressbar won't update
PostPosted: Sat Sep 08, 2012 6:54 am 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
Quote:
Updating the UI from the main thread is considered bad practice,


No... Updating from the MAIN thread is the correct way. It is updating from secondary threads that is prohibited.

The way you have structured your code is not conducive to a progress bar. In a tight loop as you have created, the is no reason the code would wait while your file is read. Put the reading loop in a new thread. Set a variable indicating how far the read has progressed, then check that var. from a timer and have the timer update the progress bar. There are many examples of such a process in this forum and the NUG archives

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Progressbar won't update
PostPosted: Sat Sep 08, 2012 10:07 am 
Offline

Joined: Fri Dec 09, 2005 6:25 pm
Posts: 357
Okay thanks. I'll take another shot at it, although I actually got it working on windows using the 2 rectangles, one of which changes size as it progresses. But using the thread should be faster.


Top
 Profile  
Reply with quote  
 Post subject: Re: Progressbar won't update
PostPosted: Sat Sep 08, 2012 12:08 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Not faster, just better. Using a thread introduces more overhead. And while using a thread is the correct approach, it isn't as simple as dropping a thread into your app and moving your code to it. (It used to be, but that has changed somewhat.) You need to ensure your thread yields time frequently enough to keep the UI updating smoothly, but not too frequently or your processing takes longer. A couple of times per second should be just about right.


Top
 Profile  
Reply with quote  
 Post subject: Re: Progressbar won't update
PostPosted: Sun Sep 09, 2012 3:56 pm 
Offline

Joined: Wed May 20, 2009 11:02 am
Posts: 423
This is a sample project following the instructions found in the blog post of the link I gave above: https://dl.dropbox.com/u/3800071/Forums/UpdateProgressBarCorrectly.rbp

_________________
Using RS2011r4.3 on Windows7.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group