The Task Parallel Library TPL provides dataflow components to help increase the robustness of concurrency-enabled applications. This dataflow model promotes actor-based programming by providing in-process message passing for coarse-grained dataflow and pipelining tasks.
The dataflow components build on the types and scheduling infrastructure of the TPL and integrate with the CVisual Basic, and F language support for asynchronous programming. These dataflow components are useful when you have multiple operations that must communicate with one видео поцелуй сексуальнымы губами asynchronously or when you want to process data as it becomes available.
For example, consider an application that processes image data from a web camera. By using видео поцелуй сексуальнымы губами dataflow model, the application can process image frames as they become available. If the application enhances image frames, for example, by performing light correction or red-eye reduction, you can create a pipeline видео поцелуй сексуальнымы губами dataflow components.
Each stage of the pipeline might use more coarse-grained parallelism functionality, such as the functionality that is provided by the TPL, to transform the image.
It describes the programming model, the predefined dataflow block types, and how to configure dataflow blocks to meet the specific requirements of your applications. Dataflow namespace is not distributed with. To install the System. Alternatively, to install it using the. It also gives you explicit control over how data is buffered and moves around the system.
To better understand the dataflow programming model, видео поцелуй сексуальнымы губами an application that asynchronously loads images from disk and creates a composite of those images.
Traditional programming models typically require that you use callbacks and synchronization objects, such as locks, to coordinate tasks and access to shared data. By using the dataflow programming model, you can create dataflow objects that process images as they are read from disk. Under the dataflow model, you declare how data is handled when it becomes available, and also any dependencies between data. Because the runtime manages dependencies between data, you can often avoid the requirement to synchronize access to shared data.
Видео поцелуй сексуальнымы губами addition, because the runtime schedules work based on the asynchronous видео поцелуй сексуальнымы губами of data, dataflow can improve responsiveness and throughput by efficiently managing the underlying threads.
For an example that uses the dataflow programming model to implement image processing in a Windows Forms application, see Walkthrough: Using Dataflow in a Windows Forms Application. The TPL Dataflow Library consists of dataflow blockswhich are data structures that buffer and process data. The TPL defines three kinds of dataflow blocks: A source block acts as a source of data and can be read from.
A target block acts as a receiver of data and can be written to. A propagator block acts as both a source block and a target block, and can be read from видео поцелуй сексуальнымы губами written to. The TPL defines the System. These dataflow block types are described in this document in the section Predefined Dataflow Block Видео поцелуй сексуальнымы губами.
You can connect dataflow blocks to form pipelineswhich are linear sequences of dataflow blocks, or networkswhich are graphs of dataflow blocks. A pipeline is one form of network.
In a pipeline or network, sources asynchronously propagate data to targets as that data becomes available. LinkTo method links a source dataflow block to a target block. A source can be linked to zero or more targets; targets can be linked from zero or more sources. You can add or remove dataflow blocks to or from a pipeline or network concurrently. The predefined dataflow block types handle all thread-safety aspects of linking and unlinking.
For an example that connects dataflow blocks to form a basic pipeline, see Walkthrough: Creating a Dataflow Pipeline. For an example that connects dataflow blocks to form a more complex network, see Walkthrough: For an example that unlinks a target from a source after the source offers the target a message, see How to: LinkTo method to link a source to a target, you can supply a delegate that determines whether the target block accepts or rejects a message based on the value of that message.
This filtering mechanism is a useful way to guarantee that a dataflow block receives only certain values. For most of the predefined dataflow block types, if a source block is connected to multiple target blocks, when a target block rejects a message, the source offers that message to the next target. The order in which a source offers messages to targets is defined by the source and can vary according видео поцелуй сексуальнымы губами the type of the source. Most source block types stop offering a message after one target accepts that message.
Видео поцелуй сексуальнымы губами an example that uses filtering to process only certain messages, see Walkthrough: Because each predefined source dataflow block type guarantees that messages are propagated out in the order in which they are received, every message must be read from the source block before the source block can process the next message.
Therefore, when you use filtering to connect multiple targets to a source, make sure that at least one target block receives each message. Otherwise, your application might deadlock.
The dataflow programming model is related to the concept of message passingwhere independent components of a program communicate with one another by sending messages. One way to propagate messages among application components is to call the Post and DataflowBlock.
SendAsync methods to send messages to target dataflow blocks post Post acts synchronously; SendAsync acts asynchronously and the ReceiveReceiveAsyncand TryReceive methods to receive messages from source blocks.
You can combine these methods with dataflow pipelines or networks by sending input data to the head node a target blockand receiving output data from the terminal node of the pipeline or the terminal nodes of the network one or more source blocks.
You can also use the Choose method to read from the first of the provided sources that has data available and perform action on that data. The target block responds to an offered message in one of three ways: When the target accepts the видео поцелуй сексуальнымы губами, the OfferMessage method returns Accepted.
When the target declines the message, the Видео поцелуй сексуальнымы губами method returns Declined. When the target requires that it no longer receives any messages from the source, OfferMessage returns DecliningPermanently.
The predefined source block types do not offer messages to linked targets after such a return value is received, and they automatically unlink from such targets.
When a target block postpones the message for later use, the OfferMessage method returns Postponed. ReserveMessage method to try видео поцелуй сексуальнымы губами reserve the offered message.
At this point, the message is either still available and can be used by the target block, or the message has been taken by another target. ConsumeMessage or ReleaseReservation method, respectively. Message reservation is typically used by the dataflow block types that operate in non-greedy mode.
Non-greedy mode is explained later in this document. ConsumeMessage method to attempt to directly consume the postponed message. Dataflow blocks also support the concept of completion.
A dataflow block that is in the completed state does not perform any further work. Each видео поцелуй сексуальнымы губами block has an associated System.
Task object, known as a completion taskthat represents the completion status of the block. Because you can wait for a Task object to finish, by using completion tasks, you can wait for one or more terminal nodes of a dataflow network to finish. The IDataflowBlock interface defines the Complete видео поцелуй сексуальнымы губами, which informs the dataflow block of a request for it to complete, and the Completion property, which returns the completion task for the dataflow block.
There are two ways to determine whether видео поцелуй сексуальнымы губами dataflow block completed without error, encountered one or more errors, or was canceled. The first way is to call the Task. Wait method on the completion task in a try - catch block Try - Catch in Visual Basic.
AggregateException is thrown when this example calls Wait on the completion task. This example demonstrates the case in which an exception goes unhandled in the delegate of an execution dataflow block. We recommend that you handle exceptions in the bodies of such blocks. However, if you are видео поцелуй сексуальнымы губами to do so, the block behaves as though it was canceled and does not видео поцелуй сексуальнымы губами incoming messages. When a dataflow block is canceled explicitly, the AggregateException object contains OperationCanceledException in the InnerExceptions property.
For more information about dataflow cancellation, see Enabling Cancellation later in this document. The second way to determine the completion status of a dataflow block is to use a continuation off of the completion task, or to use the asynchronous language features of C and Visual Basic to asynchronously wait for the completion task.
видео поцелуй сексуальнымы губами The delegate that you provide to the Task. ContinueWith method takes a Task object that represents the antecedent task.
In the case of the Completion property, the delegate for the continuation takes the completion task itself. The following example resembles the previous one, except that it also uses the ContinueWith method to create a completion task that prints the status of the overall dataflow operation.
You can also use properties such as IsCanceled in the body of the continuation task to determine additional information about the completion status of a dataflow block. Handle Видео поцелуй сексуальнымы губами Thrown by Tasks. These types are divided into three categories: The following sections describe the block types that make up these categories.
Buffering blocks hold data for use by data consumers.
This class stores a first in, first out FIFO queue видео поцелуй сексуальнымы губами messages that can be written to by multiple sources or read from by multiple targets. This class is also useful when you want to broadcast a message to multiple components. Specify a Task Scheduler in a Dataflow Block.
видео поцелуй сексуальнымы губами Therefore, multiple targets receive a copy of the message. Execution blocks call a user-provided delegate for each piece of received data. This example then sets the block to the completed state and waits for all dataflow tasks to finish.
By default, these classes process messages in the order in which they are received, one message at a time. For more information about concurrent execution, see the section Specifying the Degree of Parallelism later in this document.
For видео поцелуй сексуальнымы губами example that sets the degree of parallelism to enable an execution dataflow block to process more than one message at a time, see How to:
С этим видео также смотрят:
© 2018 hsgo.ru