I am trying to learn how to use C++ .net Timers. In the example given here:
http://msdn.microsoft.com/en-us/library/system.timers.timer.elapsed.aspx
In the code where it says:
// Hook up the Elapsed event for the timer.
aTimer->Elapsed += gcnew ElapsedEventHandler( Timer1::OnTimedEvent );
It seems the += is overloaded. What does it mean in this context?
Also I dont understand why in the example in the link, the timer starts and stops repeatedly as shown in their output:
The Elapsed event was raised at 5/20/2007 8:42:27 PM
The Elapsed event was raised at 5/20/2007 8:42:29 PM
The Elapsed event was raised at 5/20/2007 8:42:31 PM
In my understanding it should just start and stop once.
It is adding an event handler to the Elapsed event for the timer.
It would be similar to something like:
if there was such a function.
The function specified in the constructor to ElapsedEventHandler is called by the timer to notify the user that the set time has elapsed.
In reference to your second question, the first paragraph in the documentation explains it:
So obviously, the logically identical statement would be: If AutoReset is set to true, the Timer raises the Elapsed event indefinitely.
Also, you can leave AutoReset set to false, and Call the Reset() function from within your event handler. This allows you to ensure that the timer callbacks do not overlap.