ActionBlock<TInput> Konstruktorer
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Överlagringar
| Name | Description |
|---|---|
| ActionBlock<TInput>(Action<TInput>) |
Initierar en ny instans av ActionBlock<TInput> klassen med den angivna åtgärden. |
| ActionBlock<TInput>(Func<TInput,Task>) |
Initierar en ny instans av ActionBlock<TInput> klassen med den angivna åtgärden. |
| ActionBlock<TInput>(Action<TInput>, ExecutionDataflowBlockOptions) |
Initierar en ny instans av ActionBlock<TInput> klassen med angivna åtgärds- och konfigurationsalternativ. |
| ActionBlock<TInput>(Func<TInput,Task>, ExecutionDataflowBlockOptions) |
Initierar en ny instans av ActionBlock<TInput> klassen med angivna åtgärds- och konfigurationsalternativ. |
ActionBlock<TInput>(Action<TInput>)
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
Initierar en ny instans av ActionBlock<TInput> klassen med den angivna åtgärden.
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))
Parametrar
- action
- Action<TInput>
Åtgärden att anropa med varje dataelement som tas emot.
Undantag
action är null.
Gäller för
ActionBlock<TInput>(Func<TInput,Task>)
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
Initierar en ny instans av ActionBlock<TInput> klassen med den angivna åtgärden.
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))
Parametrar
Undantag
action är null.
Gäller för
ActionBlock<TInput>(Action<TInput>, ExecutionDataflowBlockOptions)
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
Initierar en ny instans av ActionBlock<TInput> klassen med angivna åtgärds- och konfigurationsalternativ.
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)
Parametrar
- action
- Action<TInput>
Åtgärden att anropa med varje dataelement som tas emot.
- dataflowBlockOptions
- ExecutionDataflowBlockOptions
Alternativen för att konfigurera den här ActionBlock<TInput>.
Undantag
Exempel
I följande exempel visas hur du använder ActionBlock<TInput>(Action<TInput>, ExecutionDataflowBlockOptions) konstruktorn för att skapa ett nytt ActionBlock<TInput> objekt. Det här kodexemplet är en del av ett större exempel för avsnittet Så här: Ange graden av parallellitet i ett dataflödesblock .
// 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
Gäller för
ActionBlock<TInput>(Func<TInput,Task>, ExecutionDataflowBlockOptions)
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
- Källa:
- ActionBlock.cs
Initierar en ny instans av ActionBlock<TInput> klassen med angivna åtgärds- och konfigurationsalternativ.
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)
Parametrar
- dataflowBlockOptions
- ExecutionDataflowBlockOptions
Alternativen för att konfigurera den här ActionBlock<TInput>.