Click here to Skip to main content
15,896,359 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Day,
i'm facing a problem in the timer interval,
the timer1_Tick event is not fired according to the interval i'm giving it!!!

i created my timer by wizard(drag-drop), and in the event timer1_Tick i write:
private void timer1_Tick(object sender, EventArgs e)
        {    
            Lbl_TimeLeft.Text = counter.ToString();
            counter = counter - 1;          
        }

counter is initialized as integer with value 100.
i'm giving the interval different values (10 or 10000 millisecond) but it is not effected, the label is still changing the same

10x
Posted
Updated 30-Apr-11 6:17am
v3
Comments
Ankit Rajput 30-Apr-11 6:41am    
Please provide your code where you have created the timer.
Rojeh 30-Apr-11 6:53am    
impoved my question
NuttingCDEF 30-Apr-11 6:51am    
Not fired at all? Not fired at the right time - if so, wrong by how big an interval / how accurate do you need it?

Just in case . . . have you specified the interval in milliseconds (not seconds or any other time unit)
Rojeh 30-Apr-11 6:55am    
it is fired in wrong time, i don't know according to which time, the interval is in milliseconds (i created it by wizard) and any value i assigned it is not effecting the time of firing the event!!
NuttingCDEF 30-Apr-11 7:13am    
Presumably the counter is counting down from 100 as expected, just too fast or too slow.

Can you estimate what interval this code is actually firing at? How long does it take for the counter to get from 100 to 0?

Just to check . . . you haven't got any other code that accesses the counter variable? And no other events on the form / any of its controls that have inadvertently been linked to your timer1_Tick method? [search the relevant designer.cs to check?]

It looks like you're using System.Windows.Forms.Timers. By some reason, the accuracy of this timer is ridiculously poor. Prefer System.Timers.Timer or System.Threading.Timer.

Also, consider using a separate thread and System.Threading.Thread.Sleep. It creates much less problems then a timer. Prefer threading unless a timer is absolutely unavoidable. In most cases a timer can be totally avoided.

—SA
 
Share this answer
 
Comments
Rojeh 1-May-11 11:32am    
10x for ur valueable comments
its working :)

try this

C#
int counter = 100;
      
       private void button1_Click(object sender, EventArgs e)
       {
           timer1.Enabled = true;
       }

       private void timer1_Tick(object sender, EventArgs e)
       {
           label1.Text = counter.ToString();
           counter = counter - 1;
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900