Implement Multithreading and asynchronous processing Flashcards

1
Q

Use the Task Parallel Library (ParallelFor, Plinq, Tasks)

A

The Task Parallel Library (TPL) is a set of public types and APIs in the System.Threading and System.Threading.Tasks namespaces in the .NET Framework version 4. The purpose of the TPL is to make developers more productive by simplifying the process of adding parallelism and concurrency to applications. The TPL scales the degree of concurrency dynamically to most efficiently use all the processors that are available. In addition, the TPL handles the partitioning of the work, the scheduling of threads on theThreadPool, cancellation support, state management, and other low-level details. By using TPL, you can maximize the performance of your code while focusing on the work that your program is designed to accomplish.

Starting with the .NET Framework 4, the TPL is the preferred way to write multithreaded and parallel code. However, not all code is suitable for parallelization; for example, if a loop performs only a small amount of work on each iteration, or it doesn’t run for many iterations, then the overhead of parallelization can cause the code to run more slowly. Furthermore, parallelization like any multithreaded code adds complexity to your program execution. Although the TPL simplifies multithreaded scenarios, we recommend that you have a basic understanding of threading concepts, for example, locks, deadlocks, and race conditions, so that you can use the TPL effectively. For more information about basic parallel computing concepts, see the Parallel Computer Developer Center on MSDN.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Create Continuation Tasks

A

In asynchronous programming, it is very common for one asynchronous operation, on completion, to invoke a second operation and pass data to it. Traditionally, this has been done by using callback methods. In the Task Parallel Library, the same functionality is provided by continuation tasks. A continuation task (also known just as a continuation) is an asynchronous task that is invoked by another task, which is known as the antecedent, when the antecedent finishes.

Continuations are relatively easy to use, but are nevertheless very powerful and flexible. For example, you can:

pass data from the antecedent to the continuation

specify the precise conditions under which the continuation will be invoked or not invoked

cancel a continuation either before it starts or cooperatively as it is running

provide hints about how the continuation should be scheduled

invoke multiple continuations from the same antecedent

invoke one continuation when all or any one of multiple antecedents complete

chain continuations one after another to any arbitrary length

use a continuation to handle exceptions thrown by the antecedent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Spawn threads by using ThreadPool

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Unblock the UI

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Use Async and Await keywords

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Manage data using concurrent collections

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly