Timer
is not a function. It is a class that provides a mechanism that allows specifying a frequency of time that a given operation should be executed.
This is how the object is created by configuring what should be executed through a delegate and when executing ( TimerCallback
).
You can pass an object so that this delegate can process, but in the posted example it passes a null, since nothing is required ( null
). It is of type object
to give freedom to pass anything. This is between your code that sets Timer
, in this case Main()
, and the method that will work as a callback , in this case TimerCallback()
It is also a time that should take to run the first time, with 0 being the immediate start, which is what was passed.
And the interval between each execution is passed, in the last 2000 case it is 2 seconds since the measure is in milliseconds.
In the same class there are other ways to configure differently depending on the convenience of the moment. This is effective with several overloads of builders .
Always look for official documentation for learn about a class or method of it. It always has the explanation of what it does, which means every part of it and usually has an example of use and some care.
Understand what a delegate is an group of methods and learn why it only passes the method name and nothing else. One more question on the subject .
See what is callback . The focus is another language, but the technique is the same.
This is not the case, but there are other classes of Timer
with a slightly different mechanism.
The delegate method calls the garbage collector. This should not be done under normal conditions . If it is a course that teaches this, consider a red alert for the content, unless there is a context and explanation why there is.