Timer trouble.

This is a discussion on Timer trouble. within the C# Programming forums, part of the General Programming Boards category; The thing is, I don't understand why I should use the "+=" operator like this: Code: myTimer.Tick += new EventHandler(myFunc); ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    80

    Timer trouble.

    The thing is, I don't understand why I should use the "+=" operator like this:
    Code:
    myTimer.Tick += new EventHandler(myFunc); //myTimer.Tick = myTimer.Tick + new EventHandler(myFunc);
    Why not simply use "=" ? If anyone could share this piece of knowledge with me I would be very grateful

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Why should you use the -> operator when accessing the members of an object through a pointer in C++? I'm not a fan of the += syntax either, but it makes a bit of sense when you unsubscribe.
    Code:
    myTimer.Tick += new EventHandler(myFunc); //subscribe to Tick event
    myTimer.Tick -= new EventHandler(myFunc); //unsubscribe from Tick event
    Then again, unsubscribing by creating a new object...yeah, it really doesn't make any sort of sense.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,812
    One word: Microsoft.
    Woop?

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    80
    So Microsoft is the answer to this question ..
    Then it has nothing to do with what the operator is usually used for? I mean like this n += a is the same as n = n + a.

    Anyway, thank you both for replying.
    Last edited by antex; 05-29-2006 at 09:40 AM.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    8
    It goes without saying that .....to save memory .

    I'm a vietnamese I hope everybody will understant it .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SIGALRM and timer
    By nkhambal in forum C Programming
    Replies: 1
    Last Post: 06-30-2008, 01:23 AM
  2. Replies: 4
    Last Post: 12-20-2007, 07:55 PM
  3. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 07:25 PM
  4. Need help with a count down timer
    By GUIPenguin in forum C# Programming
    Replies: 0
    Last Post: 07-07-2006, 05:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21