Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone explain this line of code to me please? 1

Status
Not open for further replies.

PatCSharp

Programmer
Joined
May 3, 2006
Messages
5
Location
US

Can someone explain this line of code to me please?

this.myTimer.Tick += new System.EventHandler(this.myTimer_Tick);
 
System.Windows.Forms.Timer Control is essentially a new thread that notifies you on regular intervals. Its notification happens through an event called "Tick".

So when you say mytimer.Tick += new EventHandler(this.mytimer_Tick)

you are subscribing to that event. You say, "when your time (interval) has elapsed, I want to know about it"

When timer ticks - it calls

private void mytimer_Tick(object sender, EventArgs e)
{
//and this is where you do the work that happens every interval (Timer Tick)
}
 
The other thing that might be causing confusion is the += operator. These two lines are equivalent.
Code:
a = a + b;
a += b;
In the case of events, this operator subscribes you to the event. You can also remove yourself with the -= operator.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks gents for the explanation.

Now how do I mark this thread resolved?
 
click the purple star next to "Thank PatCSharp for this valuable post" or whoever gave you the answer you needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top