Skip to content

Commit deaa37d

Browse files
author
Colin Robertson
committed
Update containing article
1 parent 26c29c5 commit deaa37d

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎docs/parallel/concrt/how-to-create-a-task-that-completes-after-a-delay.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
2-
title: "How to: Create a Task that Completes After a Delay"
3-
ms.date: "11/04/2016"
2+
title: "How to: Create a task that completes after a delay"
3+
description: "Create a task that completes after a delay by using the PPL ConcRT library."
4+
ms.date: 10/19/2020
45
helpviewer_keywords: ["task_completion_event class, example", "create a task that completes after a delay, example [C++]"]
56
ms.assetid: 3fc0a194-3fdb-4eba-8b8a-b890981a985d
67
---
7-
# How to: Create a Task that Completes After a Delay
8+
# How to: Create a task that completes after a delay
89

910
This example shows how to use the [concurrency::task](../../parallel/concrt/reference/task-class.md), [concurrency::cancellation_token_source](../../parallel/concrt/reference/cancellation-token-source-class.md), [concurrency::cancellation_token](../../parallel/concrt/reference/cancellation-token-class.md), [concurrency::task_completion_event](../../parallel/concrt/reference/task-completion-event-class.md), [concurrency::timer](../../parallel/concrt/reference/timer-class.md), and [concurrency::call](../../parallel/concrt/reference/call-class.md) classes to create a task that completes after a delay. You can use this method to build loops that occasionally poll for data, introduce timeouts, delay handling of user input for a predetermined time, and so on.
1011

@@ -15,17 +16,17 @@ The following example shows the `complete_after` and `cancel_after_timeout` func
1516
> [!TIP]
1617
> For more information about the `timer` and `call` classes, which are part of the Asynchronous Agents Library, see [Asynchronous Message Blocks](../../parallel/concrt/asynchronous-message-blocks.md).
1718
18-
The `cancel_after_timeout` function builds on the `complete_after` function to cancel a task if that task does not complete before a given timeout. The `cancel_after_timeout` function creates two tasks. The first task indicates success and completes after the provided task completes; the second task indicates failure and completes after the specified timeout. The `cancel_after_timeout` function creates a continuation task that runs when the success or failure task completes. If the failure task completes first, the continuation cancels the token source to cancel the overall task.
19+
The `cancel_after_timeout` function builds on the `complete_after` function to cancel a task if that task doesn't complete before a given timeout. The `cancel_after_timeout` function creates two tasks. The first task indicates success and completes after the provided task completes. The second task indicates failure and completes after the specified timeout. The `cancel_after_timeout` function creates a continuation task that runs when the success or failure task completes. If the failure task completes first, the continuation cancels the token source to cancel the overall task.
1920

2021
[!code-cpp[concrt-task-delay#1](../../parallel/concrt/codesnippet/cpp/how-to-create-a-task-that-completes-after-a-delay_1.cpp)]
2122

2223
## Example: Compute count of prime numbers
2324

24-
The following example computes the count of prime numbers in the range [0, 100000] multiple times. The operation fails if it does not complete in a given time limit. The `count_primes` function demonstrates how to use the `cancel_after_timeout` function. It counts the number of primes in the given range and fails if the task does not complete in the provided time. The `wmain` function calls the `count_primes` function multiple times. Each time, it halves the time limit. The program finishes after the operation does not complete in the current time limit.
25+
The following example computes the count of prime numbers in the range [0, 100000] multiple times. The operation fails if it doesn't complete in a given time limit. The `count_primes` function demonstrates how to use the `cancel_after_timeout` function. It counts the number of primes in the given range and fails if the task doesn't complete in the provided time. The `wmain` function calls the `count_primes` function multiple times. Each time, it halves the time limit. The program finishes after the operation doesn't complete in the current time limit.
2526

2627
[!code-cpp[concrt-task-delay#2](../../parallel/concrt/codesnippet/cpp/how-to-create-a-task-that-completes-after-a-delay_2.cpp)]
2728

28-
When you use this technique to cancel tasks after a delay, any unstarted tasks will not start after the overall task is canceled. However, it is important for any long-running tasks to respond to cancellation in a timely manner. For more information about task cancellation, see [Cancellation in the PPL](cancellation-in-the-ppl.md).
29+
When you use this technique to cancel tasks after a delay, any unstarted tasks won't start after the overall task is canceled. However, it's important for any long-running tasks to respond to cancellation quickly. For more information about task cancellation, see [Cancellation in the PPL](cancellation-in-the-ppl.md).
2930

3031
## Complete code example
3132

0 commit comments

Comments
 (0)