Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .openpublishing.redirection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,14 @@
{
"source_path":"docs/fsharp/language-reference/signatures.md",
"redirect_url":"/dotnet/fsharp/language-reference/signature-files"
},
{
"source_path":"docs/csharp/programming-guide/concepts/threading/thread-timers.md",
"redirect_url":"/dotnet/standard/threading/timers"
},
{
"source_path":"docs/visual-basic/programming-guide/concepts/threading/thread-timers.md",
"redirect_url":"/dotnet/standard/threading/timers"
}
]
}
1 change: 0 additions & 1 deletion docs/csharp/programming-guide/concepts/threading/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Threading enables your C# program to perform concurrent processing so that you c
|[Parameters and Return Values for Multithreaded Procedures (C#)](../../../../csharp/programming-guide/concepts/threading/parameters-and-return-values-for-multithreaded-procedures.md)|Describes how to pass and return parameters with multithreaded applications.|
|[Walkthrough: Multithreading with the BackgroundWorker Component (C#)](../../../../csharp/programming-guide/concepts/threading/walkthrough-multithreading-with-the-backgroundworker-component.md)|Shows how to create a simple multithreaded application.|
|[Thread Synchronization (C#)](../../../../csharp/programming-guide/concepts/threading/thread-synchronization.md)|Describes how to control the interactions of threads.|
|[Thread Timers (C#)](../../../../csharp/programming-guide/concepts/threading/thread-timers.md)|Describes how to run procedures on separate threads at fixed intervals.|
|[Thread Pooling (C#)](../../../../csharp/programming-guide/concepts/threading/thread-pooling.md)|Describes how to use a pool of worker threads that are managed by the system.|
|[How to: Use a Thread Pool (C#)](../../../../csharp/programming-guide/concepts/threading/how-to-use-a-thread-pool.md)|Demonstrates synchronized use of multiple threads in the thread pool.|
|[Threading](../../../../../docs/standard/threading/index.md)|Describes how to implement threading in the .NET Framework.|
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void BackgroundWorker1_RunWorkerCompleted(
}
```

You can provide parameters and return values to thread-pool threads by using the optional `ByVal` state-object variable of the <xref:System.Threading.ThreadPool.QueueUserWorkItem%2A> method. Thread-timer threads also support a state object for this purpose. For information on thread pooling and thread timers, see [Thread Pooling (C#)](../../../../csharp/programming-guide/concepts/threading/thread-pooling.md) and [Thread Timers (C#)](../../../../csharp/programming-guide/concepts/threading/thread-timers.md).
You can provide parameters and return values to thread-pool threads by using the optional `ByVal` state-object variable of the <xref:System.Threading.ThreadPool.QueueUserWorkItem%2A> method. Thread-timer threads also support a state object for this purpose. For information on thread pooling and thread timers, see [Thread Pooling (C#)](../../../../csharp/programming-guide/concepts/threading/thread-pooling.md) and [Timers](../../../../standard/threading/timers.md).

## See Also
[Walkthrough: Multithreading with the BackgroundWorker Component (C#)](../../../../csharp/programming-guide/concepts/threading/walkthrough-multithreading-with-the-backgroundworker-component.md)
Expand Down
68 changes: 0 additions & 68 deletions docs/csharp/programming-guide/concepts/threading/thread-timers.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/csharp/programming-guide/concepts/threading/toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
## [Parameters and Return Values for Multithreaded Procedures](parameters-and-return-values-for-multithreaded-procedures.md)
## [Walkthrough: Multithreading with the BackgroundWorker Component](walkthrough-multithreading-with-the-backgroundworker-component.md)
## [Thread Synchronization](thread-synchronization.md)
## [Thread Timers](thread-timers.md)
## [Thread Pooling](thread-pooling.md)
### [How to: Use a Thread Pool](how-to-use-a-thread-pool.md)
2 changes: 1 addition & 1 deletion docs/standard/threading/threading-objects-and-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The .NET Framework provides a number of objects that help you create and manage
Explains the **ThreadPool** class, which enables you to request a thread to execute a task without having to do any thread management yourself.

[Timers](../../../docs/standard/threading/timers.md)
Explains how to use a **Timer** to specify a delegate to be called at a specified time.
Describes timers that can be used in a multithreaded environment.

[Monitors](http://msdn.microsoft.com/library/33fe4aef-b44b-42fd-9e72-c908e39e75db)
Explains how to use the **Monitor** class to synchronize access to a member or to build your own thread management types.
Expand Down
57 changes: 41 additions & 16 deletions docs/standard/threading/timers.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: "Timers"
ms.date: "03/30/2017"
description: Learn what .NET timers to use in a multithreaded environment.
ms.date: "07/03/2018"
ms.technology: dotnet-standard
dev_langs:
- "csharp"
Expand All @@ -10,23 +11,47 @@ helpviewer_keywords:
- "threading [.NET Framework], timers"
- "timers, about timers"
ms.assetid: 7091500d-be18-499b-a942-95366ce185e5
author: "rpetrusha"
author: "pkulikov"
ms.author: "ronpet"
Copy link
Contributor

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).

---
# 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.
Copy link
Contributor

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.


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.


.NET provides two timers to use in a multithreaded environment:

- <xref:System.Threading.Timer?displayProperty=nameWithType>, which executes a single callback method on a <xref:System.Threading.ThreadPool> thread at regular intervals.
- <xref:System.Timers.Timer?displayProperty=nameWithType>, which by default raises an event on a <xref:System.Threading.ThreadPool> thread at regular intervals.

> [!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.

The following code example starts a timer that starts after one second (1000 milliseconds) and ticks every second until you press the **Enter** key. The variable containing the reference to the timer is a class-level field, to ensure that the timer is not subject to garbage collection while it is still running. For more information on aggressive garbage collection, see <xref:System.GC.KeepAlive%2A>.

[!code-cpp[System.Threading.Timer#2](../../../samples/snippets/cpp/VS_Snippets_CLR_System/system.Threading.Timer/CPP/source2.cpp#2)]
[!code-csharp[System.Threading.Timer#2](../../../samples/snippets/csharp/VS_Snippets_CLR_System/system.Threading.Timer/CS/source2.cs#2)]
[!code-vb[System.Threading.Timer#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Threading.Timer/VB/source2.vb#2)]
> Some .NET implementations may include additional timers:
>
> - <xref:System.Windows.Forms.Timer?displayProperty=nameWithType>: a Windows Forms component that fires an event at regular intervals. The component has no user interface and is designed for use in a single-threaded environment.
> - <xref:System.Web.UI.Timer?displayProperty=nameWithType>: an ASP.NET component that performs asynchronous or synchronous web page postbacks at a regular interval.
> - <xref:System.Windows.Threading.DispatcherTimer?displayProperty=nameWithType>: a timer that is integrated into the <xref:System.Windows.Threading.Dispatcher> queue which is processed at a specified interval of time and at a specified priority.

## The System.Threading.Timer class

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 a single call to a delegate in a specified time interval. The delegate is executed on a <xref:System.Threading.ThreadPool> thread.

When you create a <xref:System.Threading.Timer?displayProperty=nameWithType> object, you specify a <xref:System.Threading.TimerCallback> delegate that defines the callback method, an optional state object that is passed to the callback, the amount of time to delay before the first invocation of the callback, and the time interval between callback invocations. To cancel a pending timer, call the <xref:System.Threading.Timer.Dispose%2A?displayProperty=nameWithType> method.

The following example creates a timer that calls the provided delegate for the first time after one second (1000 milliseconds) and then calls it every two seconds. The state object in the example 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.

[!code-cpp[System.Threading.Timer#2](../../../samples/snippets/cpp/VS_Snippets_CLR_System/system.Threading.Timer/CPP/source2.cpp#2)]
[!code-csharp[System.Threading.Timer#2](../../../samples/snippets/csharp/VS_Snippets_CLR_System/system.Threading.Timer/CS/source2.cs#2)]
[!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>.

Copy link
Contributor

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

## The System.Timers.Timer class

Another timer that can be used in a multithreaded environment is <xref:System.Timers.Timer?displayProperty=nameWithType> that by default raises an event on a <xref:System.Threading.ThreadPool> thread.

When you create a <xref:System.Timers.Timer?displayProperty=nameWithType> object, you may specify the time interval in which to raise an <xref:System.Timers.Timer.Elapsed> event. Use the <xref:System.Timers.Timer.Enabled%2A> property to indicate if a timer should raise an <xref:System.Timers.Timer.Elapsed> event. If you need an <xref:System.Timers.Timer.Elapsed> event to be raised only once after the specified interval has elapsed, set the <xref:System.Timers.Timer.AutoReset%2A> to `false`. The default value of the <xref:System.Timers.Timer.AutoReset%2A> property is `true`, which means that an <xref:System.Timers.Timer.Elapsed> event is raised regularly at the interval defined by the <xref:System.Timers.Timer.Interval%2A> property.

For more information and examples, see <xref:System.Timers.Timer?displayProperty=nameWithType>.

## See Also
<xref:System.Threading.Timer>
[Threading Objects and Features](../../../docs/standard/threading/threading-objects-and-features.md)
## See also

<xref:System.Threading.Timer?displayProperty=nameWithType>
<xref:System.Timers.Timer?displayProperty=nameWithType>
[Threading Objects and Features](threading-objects-and-features.md)
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Threading enables your Visual Basic program to perform concurrent processing so
|[Parameters and Return Values for Multithreaded Procedures (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/parameters-and-return-values-for-multithreaded-procedures.md)|Describes how to pass and return parameters with multithreaded applications.|
|[Walkthrough: Multithreading with the BackgroundWorker Component (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/walkthrough-multithreading-with-the-backgroundworker-component.md)|Shows how to create a simple multithreaded application.|
|[Thread Synchronization (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/thread-synchronization.md)|Describes how to control the interactions of threads.|
|[Thread Timers (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/thread-timers.md)|Describes how to run procedures on separate threads at fixed intervals.|
|[Thread Pooling (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/thread-pooling.md)|Describes how to use a pool of worker threads that are managed by the system.|
|[How to: Use a Thread Pool (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/how-to-use-a-thread-pool.md)|Demonstrates synchronized use of multiple threads in the thread pool.|
|[Threading](../../../../standard/threading/index.md)|Describes how to implement threading in the .NET Framework.|
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Private Sub BackgroundWorker1_RunWorkerCompleted(
End Sub
```

You can provide parameters and return values to thread-pool threads by using the optional `ByVal` state-object variable of the <xref:System.Threading.ThreadPool.QueueUserWorkItem%2A> method. Thread-timer threads also support a state object for this purpose. For information on thread pooling and thread timers, see [Thread Pooling (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/thread-pooling.md)[Thread Pooling](http://msdn.microsoft.com/library/4b8bb2c8-8ca4-457c-9afd-d11bc9a05701) and [Thread Timers (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/thread-timers.md).
You can provide parameters and return values to thread-pool threads by using the optional `ByVal` state-object variable of the <xref:System.Threading.ThreadPool.QueueUserWorkItem%2A> method. Thread-timer threads also support a state object for this purpose. For information on thread pooling and thread timers, see [Thread Pooling (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/thread-pooling.md)[Thread Pooling](http://msdn.microsoft.com/library/4b8bb2c8-8ca4-457c-9afd-d11bc9a05701) and [Timers](../../../../standard/threading/timers.md).

## See Also
[Walkthrough: Multithreading with the BackgroundWorker Component (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/walkthrough-multithreading-with-the-backgroundworker-component.md)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
## [Parameters and Return Values for Multithreaded Procedures](parameters-and-return-values-for-multithreaded-procedures.md)
## [Walkthrough: Multithreading with the BackgroundWorker Component](walkthrough-multithreading-with-the-backgroundworker-component.md)
## [Thread Synchronization](thread-synchronization.md)
## [Thread Timers](thread-timers.md)
## [Thread Pooling](thread-pooling.md)
### [How to: Use a Thread Pool](how-to-use-a-thread-pool.md)