FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ProgressBar and Timer

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Wed Oct 15, 2008 11:30 pm    Post subject: ProgressBar and Timer Reply with quote

Greetings...

I need to show a progressbar on a timer basis. I have tried a bunch of stuff, even the sample code that you have provided in the example package, however, I can not get this to work the way that I would like. Here is the sample code I am trying to get to work:
Code:

  private void DisplayProgressBar(char[] code)
  {
    //msgBox(code);
    if(code == "stop")
    {
      tmr.stop();
      tmr = null;
      //if(pBar.value == pBar.maximum)
      pBar.value = pBar.minimum;
    }
    else if(code == "start")
    {
      //pBar.value = 1;
      pBar.minimum = 1;
      pBar.maximum = 50;
      pBar.step = 200;
      if (tmr)
      {
        tmr.stop();
        tmr = null;
        pBar.value = pBar.minimum;
      }
      tmr = new Timer;
      tmr.interval = 200;
      tmr.tick ~= &tmr_tick;
      tmr.start();
    }
    //msgBox(" ");
  }
 
  private void tmr_tick(Object sender, EventArgs ea)
  {
    pBar.performStep();
    if(pBar.value == pBar.maximum)
      pBar.value = pBar.minimum;
    Application.doEvents(); // Don't lock up the window.
  }


What I would like to do is something like this,
Code:
DisplayProgressBar("start");
... Update SharedDB
... Do some calculations
DisplayProgressBar("stop");

and have the progressbar stop and continue with the rest of the code or events. The problem seems to be a lack of an event. If I uncomment the "msgBox(" ");" statement, at the end of the DisplayProgressBar function, somehow, it works. But I don't to do that. So, what is it that I am missing?

thanks,

jose
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Fri Oct 17, 2008 4:45 pm    Post subject: Re: ProgressBar and Timer Reply with quote

I think you are mixing up some concepts. Timers don't run the way you're expecting, and your Application.doEvents() is doing nothing special. You would need to use doEvents in your "calculations" to allow the timer to fire.
Back to top
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Sat Oct 18, 2008 1:11 pm    Post subject: Reply with quote

Mixing up concepts? Heck, I don't even know the concepts. Smile Is there any place that I can read more about timers?

thanks.

jic
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Mon Oct 20, 2008 10:40 pm    Post subject: Reply with quote

Timer events work like other events, they're messages posted to the windows message queue. doEvents allows messages/events to be processed. You can setup your timer to move the progress bar, and calling doEvents in a tight loop will allow messages to be processed (timer events to fire). Calling doEvents in a tight loop will probably also stall its processing, so depending on the situation, you might want to opt for threads.
-Chris
Back to top
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Tue Oct 21, 2008 8:23 am    Post subject: Reply with quote

thanks.javascript:emoticon('Idea')

jose
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group