dotnet / dotnet/dotnet-api-docs

Incorrect description about parameters in Timer() construction leading to incorrect behavior.

Open
#11,367 0 comments 0 reactions 0 assignees View on GitHub
area-System.Threading untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

### Type of issue

Code doesn't work

### Description

With reference to [Timer construction](https://learn.microsoft.com/en-us/dotnet/api/system.threading.timer.-ctor?view=netframework-4.8#system-threading-timer-ctor(system-threading-timercallback-system-object-system-int64-system-int64)), the description says as follows:

`public Timer(System.Threading.TimerCallback callback, object state, long dueTime, long period);`

`dueTime` [Int64](https://learn.microsoft.com/en-us/dotnet/api/system.int64?view=netframework-4.8)
The amount of time to delay before callback is invoked, in milliseconds. Specify [Infinite](https://learn.microsoft.com/en-us/dotnet/api/system.threading.timeout.infinite?view=netframework-4.8#system-threading-timeout-infinite) to prevent the timer from starting. Specify zero (0) to start the timer immediately.

`period` [Int64](https://learn.microsoft.com/en-us/dotnet/api/system.int64?view=netframework-4.8)
The time interval between invocations of callback, in milliseconds. Specify [Infinite](https://learn.microsoft.com/en-us/dotnet/api/system.threading.timeout.infinite?view=netframework-4.8#system-threading-timeout-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

### Article author

@dotnet-bot

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.