Skip to content

Commit 44f5734

Browse files
authored
Merge pull request #49860 from wwlpublish/bc344c1e94f6bd4363f2244b371cf9c42210c7c17ea7bb18769b8707f440beba-live
Modules/M03-implement-asynchronous-tasks
2 parents 58e2424 + 776f4cc commit 44f5734

19 files changed

+993
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.implement-asynchronous-tasks.introduction
3+
title: Introduction
4+
metadata:
5+
title: Introduction
6+
description: "Introduction."
7+
ms.date: 04/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 3
12+
content: |
13+
[!include[](includes/1-introduction.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.implement-asynchronous-tasks.get-started-asynchronous-programming
3+
title: Get started with asynchronous programming
4+
metadata:
5+
title: Get started with asynchronous programming
6+
description: "Get started with asynchronous programming."
7+
ms.date: 04/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 10
12+
content: |
13+
[!include[](includes/2-get-started-asynchronous-programming.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.implement-asynchronous-tasks.implement-asynchronous-file-input-output
3+
title: Implement asynchronous file input and output
4+
metadata:
5+
title: Implement asynchronous file input and output
6+
description: "Implement asynchronous file input and output."
7+
ms.date: 04/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 5
12+
content: |
13+
[!include[](includes/3-implement-asynchronous-file-input-output.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.implement-asynchronous-tasks.access-web-resources-asynchronously
3+
title: Access web resources asynchronously
4+
metadata:
5+
title: Access web resources asynchronously
6+
description: "Access web resources asynchronously."
7+
ms.date: 04/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 6
12+
content: |
13+
[!include[](includes/4-access-web-resources-asynchronously.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.implement-asynchronous-tasks.run-asynchronous-tasks-parallel
3+
title: Run asynchronous tasks in parallel
4+
metadata:
5+
title: Run asynchronous tasks in parallel
6+
description: "Run asynchronous tasks in parallel."
7+
ms.date: 04/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 6
12+
content: |
13+
[!include[](includes/5-run-asynchronous-tasks-parallel.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.implement-asynchronous-tasks.manage-asynchronous-parallel-tasks
3+
title: Manage asynchronous and parallel tasks
4+
metadata:
5+
title: Manage asynchronous and parallel tasks
6+
description: "Manage asynchronous and parallel tasks."
7+
ms.date: 04/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 10
12+
content: |
13+
[!include[](includes/6-manage-asynchronous-parallel-tasks.md)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.implement-asynchronous-tasks.exercise-implement-tasks-asynchronously-parallel
3+
title: Exercise - Implement tasks asynchronously and in parallel
4+
metadata:
5+
title: Exercise - Implement tasks asynchronously and in parallel
6+
description: "Exercise - Implement tasks asynchronously and in parallel."
7+
ms.date: 04/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 20
12+
content: |
13+
[!include[](includes/7-exercise-implement-tasks-asynchronously-parallel.md)]
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.implement-asynchronous-tasks.knowledge-check
3+
title: Knowledge check
4+
metadata:
5+
title: Knowledge check
6+
description: "Knowledge check."
7+
ms.date: 04/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 3
12+
quiz:
13+
title: "Check your knowledge"
14+
questions:
15+
- content: "What is the purpose of using the `async` and `await` keywords in C# for file I/O operations?"
16+
choices:
17+
- content: "To create asynchronous methods that can perform file I/O operations without blocking the main thread."
18+
isCorrect: true
19+
explanation: "Correct. The `async` and `await` keywords allow for the creation of asynchronous methods that perform file I/O operations without blocking the main thread, improving application performance and responsiveness."
20+
- content: "To perform file I/O operations synchronously."
21+
isCorrect: false
22+
explanation: "Incorrect. The `async` and `await` keywords are used to perform operations asynchronously, not synchronously."
23+
- content: "To block the main thread until the file I/O operation is complete."
24+
isCorrect: false
25+
explanation: "Incorrect. The `async` and `await` keywords are used to perform operations without blocking the main thread."
26+
- content: "What is the purpose of the `HttpClient` class in C#?"
27+
choices:
28+
- content: "To make nonblocking calls to web resources asynchronously."
29+
isCorrect: true
30+
explanation: "Correct. The `HttpClient` class in C# is designed for asynchronous use, allowing nonblocking calls to web resources."
31+
- content: "To create multiple instances for each request to web resources."
32+
isCorrect: false
33+
explanation: "Incorrect. Creating a single instance of `HttpClient` and using it throughout the application is recommended."
34+
- content: "To block the UI thread while making calls to web resources."
35+
isCorrect: false
36+
explanation: "Incorrect. The `HttpClient` class is designed for asynchronous use, allowing nonblocking calls to web resources."
37+
- content: "What is the purpose of the Task Parallel Library (TPL) in C#?"
38+
choices:
39+
- content: "To provide a set of public types and APIs for managing database connections."
40+
isCorrect: false
41+
explanation: "Incorrect. The TPL doesn't manage database connections. It simplifies the process of adding parallelism and concurrency to applications."
42+
- content: "To provide a set of public types and APIs in the `System.Threading` and `System.Threading.Tasks` namespaces that simplify the process of adding parallelism and concurrency to applications."
43+
isCorrect: true
44+
explanation: "Correct. The TPL is designed to make developers more productive by simplifying the process of adding parallelism and concurrency to applications."
45+
- content: "To provide a set of public types and APIs for handling user interface events."
46+
isCorrect: false
47+
explanation: "Incorrect. The TPL isn't designed for handling user interface events. It's used for simplifying the process of adding parallelism and concurrency to applications."
48+
- content: "What is a common pitfall in data and task parallelism?"
49+
choices:
50+
- content: "Avoiding writing to shared memory locations."
51+
isCorrect: false
52+
explanation: "Incorrect. Writing to shared memory locations in parallel tasks can lead to race conditions and should be avoided."
53+
- content: "Assuming parallel is always faster."
54+
isCorrect: true
55+
explanation: "Correct. It's a common pitfall to assume that parallel tasks always run faster than sequential ones."
56+
- content: "Assuming parallel is always slower."
57+
isCorrect: false
58+
explanation: "Incorrect. It's a common misconception that parallel is always faster, not slower."
59+
- content: "What is the purpose of using `Parallel.ForEachAsync` and `Task.WhenAll` in a C# application?"
60+
choices:
61+
- content: "To connect the application to a database."
62+
isCorrect: false
63+
explanation: "Incorrect. These methods aren't used for database connections, but for managing tasks."
64+
- content: "To implement data parallelism."
65+
isCorrect: true
66+
explanation: "Correct. `Parallel.ForEachAsync` and `Task.WhenAll` are used to manage multiple tasks concurrently, implementing data parallelism."
67+
- content: "To create a user interface for the application."
68+
isCorrect: false
69+
explanation: "Incorrect. These methods aren't used for creating user interfaces, but for managing tasks."
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.implement-asynchronous-tasks.summary
3+
title: Summary
4+
metadata:
5+
title: Summary
6+
description: "Summary."
7+
ms.date: 04/07/2025
8+
author: wwlpublish
9+
ms.author: cahowd
10+
ms.topic: unit
11+
durationInMinutes: 2
12+
content: |
13+
[!include[](includes/9-summary.md)]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Asynchronous and parallel programming are powerful techniques that can enhance the performance and responsiveness of your applications. In C#, these techniques are made simpler and more accessible through the use of keywords like `async` and `await`, and libraries like the Task Parallel Library (TPL).
2+
3+
Imagine you're signed up to help a non-profit company with a software project. Before the project kicks off, you decide to update your programming skills by developing a banking app. To practice your asynchronous programming skills, you're going implement asynchronous versions of helper classes that implement file backup and restore processes.
4+
5+
The topics covered in this module include:
6+
7+
- Introduction to asynchronous programming in C#.
8+
- Implementing asynchronous file input and output in C#.
9+
- Asynchronous access to web resources using `HttpClient` in C#.
10+
- Implementing parallel programming and asynchronous tasks in C#.
11+
- Managing and handling exceptions in asynchronous and parallel tasks in C#.
12+
- Implementing data parallelism in C# using `Parallel.ForEachAsync` and `Task.WhenAll`.
13+
14+
After completing this module, you’ll be able to:
15+
16+
- Implement asynchronous programming in C# using the `async` and `await` keywords.
17+
- Perform asynchronous file input and output operations and access web resources asynchronously in C#.
18+
- Use the Task Parallel Library (TPL) in C# for parallel programming and managing concurrent data structures.
19+
- Identify common pitfalls in parallel programming and handle exceptions in async and parallel tasks.
20+
- Implement data parallelism in a C# application as part of a hands-on exercise.

0 commit comments

Comments
 (0)