dotnet / dotnet/dotnet-api-docs

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

Aperta
#11,367 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
area-System.Threading untriaged
Lingua principale
C#
Stelle
950
Fork
1.7k
Merge medio
2g 19h
PR unite (30g)
52

Descrizione

### 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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia da xml/System.Threading/Timer.xml e dalla documentazione collegata del costruttore di Timer, quindi riproduci le due chiamate descritte nell’issue per verificare il comportamento dei parametri. Confronta la semantica documentata di dueTime e period con i risultati osservati e, se necessario, con l’implementazione; il lavoro è completo quando la pagina dell’API descrive accuratamente il comportamento verificato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
58/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.