New topic: 

Progress Bar in Windows?

<http://forums.realsoftware.com/viewtopic.php?t=47749>

         Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic          Author  
Message        jjfcpa          Post subject: Progress Bar in Windows?Posted: 
Tue Apr 30, 2013 1:47 pm                         
Joined: Tue Apr 17, 2007 9:19 pm
Posts: 430                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                timhare          Post subject: 
Re: Progress Bar in Windows?Posted: Tue Apr 30, 2013 2:51 pm                    
     
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12270
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                jjfcpa          Post subject: 
Re: Progress Bar in Windows?Posted: Tue Apr 30, 2013 8:14 pm                    
     
Joined: Tue Apr 17, 2007 9:19 pm
Posts: 430                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                jjfcpa          Post subject: 
Re: Progress Bar in Windows?Posted: Tue Apr 30, 2013 8:28 pm                    
     
Joined: Tue Apr 17, 2007 9:19 pm
Posts: 430                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                timhare          Post subject: 
Re: Progress Bar in Windows?Posted: Tue Apr 30, 2013 10:24 pm                   
      
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12270
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             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to