Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Nov 17, 2017 12:05 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Progress Bar in Windows?
PostPosted: Tue Apr 30, 2013 1:47 pm 
Offline

Joined: Tue Apr 17, 2007 9:19 pm
Posts: 437
I have a progress bar this is working perfectly in OSX, but does not show up in Windows.

It may be my coding, but I'm hoping it something else. Here is the way it works...

1. Call a Window

2. Window in #1 calls the progress bar window and passes it a parameter that tells it what method to call in Window called in #1

3. Progress Bar windows calls method in Window called in #1

This allows me to have a generic progress bar that I can call from any Window. Works great in OSX, but as I stated, in Windows, the code still runs but the progress bar does not show.

If you want a copy of the progress bar window, I'd be happy to send to you.


Top
 Profile  
Reply with quote  
 Post subject: Re: Progress Bar in Windows?
PostPosted: Tue Apr 30, 2013 2:51 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
The standard answer here is, "Put the method call into a thread." On Windows, the progressbar (as well as the rest of the UI) relies on being serviced by the "event loop", which runs in the main thread. Any other code running in the main thread causes the event loop to be delayed until that code finishes. So you see no UI updates during that time. Putting the code into a thread allows the event loop to share time with that code.


Top
 Profile  
Reply with quote  
 Post subject: Re: Progress Bar in Windows?
PostPosted: Tue Apr 30, 2013 8:14 pm 
Offline

Joined: Tue Apr 17, 2007 9:19 pm
Posts: 437
Tim

Very frustrating ...

I hope you can set me straight.

I have a form with a timer and thread on it, and of course, a progress bar.

In the startup method, I call a ShowProgress method which has the following code in it.

PBValue = 0
PBMax = 1000
PBUpdate = True
self.Thread1.Run

The first 3 items are properties of the form.

In the run method of the thread I have the following code.

self.Timer1.Mode = timer.ModeMultiple
ScanAssets()

The method ScanAssets is where are the processing takes place. In this method, I update the properties PBValue, PBMax, and PBUpdate in a loop that runs.

Finally, in the Timer.Action, I have the following code.

if Thread1.State <> 4 then
if PBUpdate then
pb1.Maximum = PBMax
pb1.Value = PBValue
PBUpdate = False
end
else
self.Timer1.Mode = 0
pb1.Value = pb1.Maximum
end

What appears to be happening is that the progressbar displays and runs with a sort of oscillating display. It definitely is not updating and I can tell that the timer.action is not running. I have the timer period set to 1000 and almost 5000 records that are being processed. Even if I change the timer period to 10000, the display is not updating. From what I can tell, the timer.action is only being run when the ScanAssets() method ends.

Any help would be appreciated.


Top
 Profile  
Reply with quote  
 Post subject: Re: Progress Bar in Windows?
PostPosted: Tue Apr 30, 2013 8:28 pm 
Offline

Joined: Tue Apr 17, 2007 9:19 pm
Posts: 437
Tim

Does it matter if the code in the ScanAssets() updates some controls (text boxes) on the window? I was reading that the code in the thread can not update any controls and since I do update some controls is that what's causing the progressbar to not update properly?


Top
 Profile  
Reply with quote  
 Post subject: Re: Progress Bar in Windows?
PostPosted: Tue Apr 30, 2013 10:24 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
You shouldn't update controls from the thread. But that won't block the progressbar. More likely your thread isn't yielding enough time to the UI. This can take a little trial and error to get the right balance of throughput and smooth display updating.

Either reduce the priority of the thread, or put in an occasional app.YieldNextThread call. If you go with yielding, do it every X milliseconds, not every time through the loop. Updating the display a few times per second is enough to produce a pleasing progress indicator.


Top
 Profile  
Reply with quote  
 Post subject: Re: Progress Bar in Windows?
PostPosted: Wed May 01, 2013 7:57 am 
Offline

Joined: Tue Apr 17, 2007 9:19 pm
Posts: 437
Tim

Thanks for your help. As usual you provide the solution I was looking for. By putting the app.yieldtonextthread in my loop, I now have a progressbar that is updating properly. I will need to tweak it a bit because I don't want to slow things down too much, which is what is happening now. I'm going to put in some code to only do this every few hundred records.

One other complication is that my app allows the user to create an unlimited number of data files - it's an accounting application and they will be creating files for their clients. The files may be on a local drive or a network drive and if it's on a network, I probably don't want to slow it down too much because the network will do that for me.

Nevertheless, you've got me going in the right direction and I greatly appreciate it.

One other thing I just might mention. I originally had my progress bar on a sheet window in OSX and just assumed that it would show up as a modal window in Windows. However, that wasn't the case ... it didn't show up at all. Do you think it's due to the same reason that the thread was not allowing the UI to update?


Top
 Profile  
Reply with quote  
 Post subject: Re: Progress Bar in Windows?
PostPosted: Wed May 01, 2013 12:15 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
I'd recommend using either Ticks or Microseconds to determine when to yield, rather than the number of records.


Top
 Profile  
Reply with quote  
 Post subject: Re: Progress Bar in Windows?
PostPosted: Wed May 01, 2013 3:38 pm 
Offline

Joined: Tue Apr 17, 2007 9:19 pm
Posts: 437
That's a good idea then it isn't affected by the speed of the computer...


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 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