Progressbar updation problem

  • Thread starter Thread starter Chintan
  • Start date Start date
C

Chintan

HI,

I am getting problem with splash screen showing while some other
process is going on. I have a timer which is not getting fired at the
interval set, when the long process is running on.

My code looks something like this,

btn_Click(object sender, System.EventArgs e)
{
timer1.Interval=100;
timer1.enabled=true;
panel1.visible=true;
// Some long running process
// While this process is going on i want to show progress bar updating
}

private void timer1_Tick(object sender, System.EventArgs e)
{
if (panel1.Visible == true)
{
if(progressBar1.Value==10)
{
progressBar1.Value=0;
}
progressBar1.Value = progressBar1.Value + 1;
}
}

So, while the long running process is going on, after every 100
milliseconds, the timer1_Tick should fire, and update the progressbar,
but the event is not getting fired at all. What am i doing wrong? How
can i solve the problem?

Thanks in Advance.
 
Hi,

The problem here is that, the timer1_Tick event fires only after the
long running process is completed, before that the event would not fire
and the progress bar value will not be updated. I want the progress bar
value to be updated when the long running process is going on.

And once the long running process is over, i dont need the progressbar
at all, so there is no use of timer firing after the long running
process is over. So, there is no use of Progressbar.Update().

Thanks.
Chintan
 
In that case there's something going on in your application that you've not
told us about.

When asking for assistance, it helps to include ALL relevant information.
 
I suspect that your long running process is located in the UI thread, is
it? Due to the fact that Forms.Timer (not System.Threading.Timer) also
works in the UI thread (it sends WM_TIMER message to the message queue)
you are just blocking it with your long operations. There are two
possible solutions for that problem:-

1. try to move long running process into separate thread;
2. in the long running process periodically call Application.DoEvents to
process all messages in the message queue.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
Back
Top