VICKY Shastri
VICKY Shastri

Reputation: 143

how to give interval in a program process using timer control c#/.net

how can i give interval in a program process using timer control.

Like:

while(progressBar1.Value ! = 10)
{
    progressBar1.Value = progressBar1.value + 1;
   //i want to give 10 seconds interval here
}

Upvotes: 0

Views: 538

Answers (1)

Jeremy Thompson
Jeremy Thompson

Reputation: 65712

-Drag a Timer onto your form or if its not winforms simply instantiate a Timer control in code. -Click it and press F4 to bring up the properties.
-Set the Timers Interval property to 10000 or programmatically timer1.Interval = 10000;.
-Set the Enabled property to True or programmatically timer1.Enabled = true;.
-To view the Timers events click the lightning bolt icon (in the properties window)

Then double click the Tick event (the row in the property window called Tick). This will take you to the Timers_Tick event where you can add this code:

//This event will fire each 10 seconds
private void timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) 
{
 if (progressBar1.Value ! = 10)
 {
    progressBar1.Value = progressBar1.value + 1;
 }
}

Upvotes: 3

Related Questions