-
Notifications
You must be signed in to change notification settings - Fork 6k
Removed duplicate thread timers topics #6268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really great, @pkulikov! We really appreciate your doing this work. I've left a number of comments and suggestions.
| - "timers, about timers" | ||
| ms.assetid: 7091500d-be18-499b-a942-95366ce185e5 | ||
| author: "rpetrusha" | ||
| ms.author: "ronpet" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can list yourself in the author field here. (thought not in the ms.author field).
| ms.author: "ronpet" | ||
| --- | ||
| # Timers | ||
| Timers are lightweight objects that enable you to specify a delegate to be called at a specified time. A thread in the thread pool performs the wait operation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that I would add this section back and add to it, something like:
".NET Standard 2.0 includes two timers:
- <xref:System.Threading.Timer?displayProperty=fullName>, which executes a single callback method on a thread pool thread at regular intervals.
- <xref:System.Timers.Timer?displayProperty=fullName>, which fires an event and executes the code in one or more event sinks at regular intervals.
| --- | ||
| # Timers | ||
| Timers are lightweight objects that enable you to specify a delegate to be called at a specified time. A thread in the thread pool performs the wait operation. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the introduction added back, I'd add a header here:
## The System.Threading.Timer class
docs/standard/threading/timers.md
Outdated
| # Timers | ||
| Timers are lightweight objects that enable you to specify a delegate to be called at a specified time. A thread in the thread pool performs the wait operation. | ||
|
|
||
| The <xref:System.Threading.Timer?displayProperty=nameWithType> class enables you to continuously call a delegate at specified time intervals. You also can use this class to schedule the single call to a delegate in a specified time interval. The delegate is executed each time on a <xref:System.Threading.ThreadPool> thread. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the single call --> a single call
executed each time --> executed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first deleted paragraph is still important, since it provides background for using the control that doesn't have to be gleaned from the example. I'd include a modified version:
You create a <xref:System.Threading.Timer?displayProperty=nameWithType> object by passing one of its constructors a <xref:System.Threading.TimerCallback> delegate that defines the callback method, an optional state object that is passed to the callback, an initial raise time, and a time representing the period between callback invocations. To cancel a pending timer, call the <xref:System.Threading.Timer.Dispose%2A?displayProperty=nameWithType> method.
docs/standard/threading/timers.md
Outdated
|
|
||
| The <xref:System.Threading.Timer?displayProperty=nameWithType> class enables you to continuously call a delegate at specified time intervals. You also can use this class to schedule the single call to a delegate in a specified time interval. The delegate is executed each time on a <xref:System.Threading.ThreadPool> thread. | ||
|
|
||
| The following example creates a timer that starts after one second (1000 milliseconds) and calls the provided delegate every two seconds. When you create a timer, you can provide the object that will be passed to every delegate call. In the example, such an object is used to count how many times the delegate is called. The timer is stopped when the delegate has been called at least 10 times. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the object that will be passed --> an object that is passed
| [!code-vb[System.Threading.Timer#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Threading.Timer/VB/source2.vb#2)] | ||
|
|
||
| For more information and examples, see <xref:System.Threading.Timer?displayProperty=nameWithType>. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add another level-2 head here:
## The System.Timers.Timer class
| Using the <xref:System.Threading.Timer?displayProperty=nameWithType> class is straightforward. You create a **Timer**, passing a <xref:System.Threading.TimerCallback> delegate to the callback method, an object representing state that will be passed to the callback, an initial raise time, and a time representing the period between callback invocations. To cancel a pending timer, call the **Timer.Dispose** function. | ||
|
|
||
| > [!NOTE] | ||
| > There are two other timer classes. The <xref:System.Windows.Forms.Timer?displayProperty=nameWithType> class is a control that works with visual designers and is meant to be used in user interface contexts; it raises events on the user interface thread. The <xref:System.Timers.Timer?displayProperty=nameWithType> class derives from <xref:System.ComponentModel.Component>, so it can be used with visual designers; it also raises events, but it raises them on a <xref:System.Threading.ThreadPool> thread. The <xref:System.Threading.Timer?displayProperty=nameWithType> class makes callbacks on a <xref:System.Threading.ThreadPool> thread and does not use the event model at all. It also provides a state object to the callback method, which the other timers do not. It is extremely lightweight. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though not as well done here as it should have been, the note was intended to differentiate between timer types in the .NET Framework, which was an enormous source of confusion and complaint. I think it is still useful to add a note before the first level-2 head:
> [!NOTE]
> Some .NET implementations may include additional `Timer` classes. See the <xref:System.Threading.Timer?displayProperty=nameWithType> class for their differences and usage scenarios.
|
Closing and reopening to begin new build. |
|
@rpetrusha I liked your feedback a lot; it helped to make the topic much better. Thanks! As I've added a lot of new information to the topic, please review it again. |
|
Thanks for making the corrections, @pkulikov. I'll review your PR sometime tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, @pkulikov, so I'm going to merge it now. Thank you so much for doing this; you've not only eliminated triplication in the documentation, but you've made the single version of the topic much better!
This PR cleans both the C# and VB Guides from the duplicate thread timer topics:
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/threading/thread-timers
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/concepts/threading/thread-timers
Also updates the related topic in the .NET Guide (with new code snippets by dotnet/samples#156):
https://docs.microsoft.com/en-us/dotnet/standard/threading/timers
That topic is simplified and only mentions two timers:
System.Threading.TimerandSystem.Timers.Timerthat are ones recommended for the use in a multithreaded environment.Contributes to #6180