Description
Type of issue
Code doesn't work
Description
With reference to Timer construction, the description says as follows:
public Timer(System.Threading.TimerCallback callback, object state, long dueTime, long period);
dueTime
Int64
The amount of time to delay before callback is invoked, in milliseconds. Specify Infinite to prevent the timer from starting. Specify zero (0) to start the timer immediately.
period
Int64
The time interval between invocations of callback, in milliseconds. Specify Infinite to disable periodic signaling.
Actual Behavior:
When called: Timer(callback, state, 0, 5000);
--> Timer starts after 5 seconds and the callback are continuous without any delay. (Observed more than 20 each seconds, bombarded with callbacks)
However, it should have been reverse, i.e. start timer immediately and receive callback every 5 seconds.
When called: Timer(callback, state, 5000, 0);
--> Timer starts instantaneously, and the callbacks are received every 5 seconds.
However, it should have been timer start after 5 seconds and receive callback continuously.
The behavior is easily reproducible on a sample.
So, it is very evident that, either the documentation is wrong where the parameters dueTime
and period
are reversed, or the implementation is wrong in which case also the parameters are reversed. In any case the documentation is not matching the code behavior.
Page URL
https://learn.microsoft.com/en-us/dotnet/api/system.threading.timer.-ctor?view=netframework-4.8
Content source URL
https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Threading/Timer.xml
Document Version Independent Id
832e8e3c-e498-bbea-44dc-81c60d696705
Platform Id
c1d51610-7405-6c58-a3a3-dc864e3e0caf