ActionBlock<TInput> Constructeurs
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Surcharges
| Nom | Description |
|---|---|
| ActionBlock<TInput>(Action<TInput>) |
Initialise une nouvelle instance de la ActionBlock<TInput> classe avec l’action spécifiée. |
| ActionBlock<TInput>(Func<TInput,Task>) |
Initialise une nouvelle instance de la ActionBlock<TInput> classe avec l’action spécifiée. |
| ActionBlock<TInput>(Action<TInput>, ExecutionDataflowBlockOptions) |
Initialise une nouvelle instance de la ActionBlock<TInput> classe avec les options d’action et de configuration spécifiées. |
| ActionBlock<TInput>(Func<TInput,Task>, ExecutionDataflowBlockOptions) |
Initialise une nouvelle instance de la ActionBlock<TInput> classe avec les options d’action et de configuration spécifiées. |
ActionBlock<TInput>(Action<TInput>)
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
Initialise une nouvelle instance de la ActionBlock<TInput> classe avec l’action spécifiée.
public:
ActionBlock(Action<TInput> ^ action);
public ActionBlock(Action<TInput> action);
new System.Threading.Tasks.Dataflow.ActionBlock<'Input> : Action<'Input> -> System.Threading.Tasks.Dataflow.ActionBlock<'Input>
Public Sub New (action As Action(Of TInput))
Paramètres
- action
- Action<TInput>
Action à appeler avec chaque élément de données reçu.
Exceptions
action a la valeur null.
S’applique à
ActionBlock<TInput>(Func<TInput,Task>)
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
Initialise une nouvelle instance de la ActionBlock<TInput> classe avec l’action spécifiée.
public:
ActionBlock(Func<TInput, System::Threading::Tasks::Task ^> ^ action);
public ActionBlock(Func<TInput,System.Threading.Tasks.Task> action);
new System.Threading.Tasks.Dataflow.ActionBlock<'Input> : Func<'Input, System.Threading.Tasks.Task> -> System.Threading.Tasks.Dataflow.ActionBlock<'Input>
Public Sub New (action As Func(Of TInput, Task))
Paramètres
Exceptions
action a la valeur null.
S’applique à
ActionBlock<TInput>(Action<TInput>, ExecutionDataflowBlockOptions)
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
Initialise une nouvelle instance de la ActionBlock<TInput> classe avec les options d’action et de configuration spécifiées.
public:
ActionBlock(Action<TInput> ^ action, System::Threading::Tasks::Dataflow::ExecutionDataflowBlockOptions ^ dataflowBlockOptions);
public ActionBlock(Action<TInput> action, System.Threading.Tasks.Dataflow.ExecutionDataflowBlockOptions dataflowBlockOptions);
new System.Threading.Tasks.Dataflow.ActionBlock<'Input> : Action<'Input> * System.Threading.Tasks.Dataflow.ExecutionDataflowBlockOptions -> System.Threading.Tasks.Dataflow.ActionBlock<'Input>
Public Sub New (action As Action(Of TInput), dataflowBlockOptions As ExecutionDataflowBlockOptions)
Paramètres
- action
- Action<TInput>
Action à appeler avec chaque élément de données reçu.
- dataflowBlockOptions
- ExecutionDataflowBlockOptions
Options avec lesquelles configurer ce ActionBlock<TInput>.
Exceptions
Exemples
L’exemple suivant montre comment utiliser le ActionBlock<TInput>(Action<TInput>, ExecutionDataflowBlockOptions) constructeur pour créer un ActionBlock<TInput> objet. Cet exemple de code fait partie d’un exemple plus large fourni pour la rubrique How to : Specify the Degree of Parallelism in a Dataflow Block topic.
// Performs several computations by using dataflow and returns the elapsed
// time required to perform the computations.
static TimeSpan TimeDataflowComputations(int maxDegreeOfParallelism,
int messageCount)
{
// Create an ActionBlock<int> that performs some work.
var workerBlock = new ActionBlock<int>(
// Simulate work by suspending the current thread.
millisecondsTimeout => Thread.Sleep(millisecondsTimeout),
// Specify a maximum degree of parallelism.
new ExecutionDataflowBlockOptions
{
MaxDegreeOfParallelism = maxDegreeOfParallelism
});
// Compute the time that it takes for several messages to
// flow through the dataflow block.
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
for (int i = 0; i < messageCount; i++)
{
workerBlock.Post(1000);
}
workerBlock.Complete();
// Wait for all messages to propagate through the network.
workerBlock.Completion.Wait();
// Stop the timer and return the elapsed number of milliseconds.
stopwatch.Stop();
return stopwatch.Elapsed;
}
' Demonstrates how to specify the maximum degree of parallelism
' when using dataflow.
Friend Class Program
' Performs several computations by using dataflow and returns the elapsed
' time required to perform the computations.
Private Shared Function TimeDataflowComputations(ByVal maxDegreeOfParallelism As Integer, ByVal messageCount As Integer) As TimeSpan
' Create an ActionBlock<int> that performs some work.
Dim workerBlock = New ActionBlock(Of Integer)(Function(millisecondsTimeout) Pause(millisecondsTimeout), New ExecutionDataflowBlockOptions() With { .MaxDegreeOfParallelism = maxDegreeOfParallelism})
' Simulate work by suspending the current thread.
' Specify a maximum degree of parallelism.
' Compute the time that it takes for several messages to
' flow through the dataflow block.
Dim stopwatch As New Stopwatch()
stopwatch.Start()
For i As Integer = 0 To messageCount - 1
workerBlock.Post(1000)
Next i
workerBlock.Complete()
' Wait for all messages to propagate through the network.
workerBlock.Completion.Wait()
' Stop the timer and return the elapsed number of milliseconds.
stopwatch.Stop()
Return stopwatch.Elapsed
End Function
Private Shared Function Pause(ByVal obj As Object)
Thread.Sleep(obj)
Return Nothing
End Function
S’applique à
ActionBlock<TInput>(Func<TInput,Task>, ExecutionDataflowBlockOptions)
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
- Source:
- ActionBlock.cs
Initialise une nouvelle instance de la ActionBlock<TInput> classe avec les options d’action et de configuration spécifiées.
public:
ActionBlock(Func<TInput, System::Threading::Tasks::Task ^> ^ action, System::Threading::Tasks::Dataflow::ExecutionDataflowBlockOptions ^ dataflowBlockOptions);
public ActionBlock(Func<TInput,System.Threading.Tasks.Task> action, System.Threading.Tasks.Dataflow.ExecutionDataflowBlockOptions dataflowBlockOptions);
new System.Threading.Tasks.Dataflow.ActionBlock<'Input> : Func<'Input, System.Threading.Tasks.Task> * System.Threading.Tasks.Dataflow.ExecutionDataflowBlockOptions -> System.Threading.Tasks.Dataflow.ActionBlock<'Input>
Public Sub New (action As Func(Of TInput, Task), dataflowBlockOptions As ExecutionDataflowBlockOptions)
Paramètres
- dataflowBlockOptions
- ExecutionDataflowBlockOptions
Options avec lesquelles configurer ce ActionBlock<TInput>.