View previous topic :: View next topic |
Author |
Message |
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Wed Oct 15, 2008 11:30 pm Post subject: ProgressBar and Timer |
|
|
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 |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Fri Oct 17, 2008 4:45 pm Post subject: Re: ProgressBar and Timer |
|
|
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 |
|
|
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Sat Oct 18, 2008 1:11 pm Post subject: |
|
|
Mixing up concepts? Heck, I don't even know the concepts. Is there any place that I can read more about timers?
thanks.
jic |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Mon Oct 20, 2008 10:40 pm Post subject: |
|
|
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 |
|
|
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Tue Oct 21, 2008 8:23 am Post subject: |
|
|
thanks.javascript:emoticon('')
jose |
|
Back to top |
|
|
|