Saturday, 10 December 2016

C# Timer

Tags

Hello guys ,
Welcome to http://mydotnetwebapp.blogspot.in . This Article is totally regarding about " Timer control " which is the most important part in c# Programming.

C# Timer Control


1) use :  A) C# Timer control is use for designing Time Oriented windows applications .
B) A Timer control raises an event at a given time interval . If you need to execute some code after certain interval of time so , you can use a Timer control .

2) namespace : System.Timers ; 

3) Properties (Behavior) : C# Timer control has two important properties  1) Enabled  2) Interval
Enabled property of timer indicate that Timer is currently Running . We can set this property to true for start and false for stop.
Interval property indicates time on in milliseconds.
1 second  = 1000 milliseconds . 
2 second = 2000 milliseconds  and so on ...

Timer t1 = new Timer();
t1.Interval = 2000;
timer1.Enabled = true;

4) Example : C# Timer control

C# Timer

C# Timer Properties




Example :

 //For Blinking Label
        private void timer1_Tick(object sender, EventArgs e)
        {
            Random rm = new Random(); 
            int a = rm.Next(0,255);    
/* generate random number from 0 to 255 */
            int b = rm.Next(0, 255);
            int c = rm.Next(0, 255);

            label1.ForeColor = Color.FromArgb(a,b,c);
/* label1 starts blinking with random colors .*/
        }

 Set Timer Properties : 
1) enabled = true ;
2) Interval = 100 ; 

5) Event : 

1)  Disposed :  When the component is Disposed by a call to the Dispose Method . 

2)  Elapsed :  When the Interval Elapses .


EmoticonEmoticon