다음을 통해 공유


ActionBlock<TInput> 생성자

정의

오버로드

ActionBlock<TInput>(Action<TInput>)

지정한 동작을 사용하여 ActionBlock<TInput> 클래스의 새 인스턴스를 초기화합니다.

ActionBlock<TInput>(Func<TInput,Task>)

지정한 동작을 사용하여 ActionBlock<TInput> 클래스의 새 인스턴스를 초기화합니다.

ActionBlock<TInput>(Action<TInput>, ExecutionDataflowBlockOptions)

지정된 작업 및 구성 옵션을 사용하여 ActionBlock<TInput> 클래스의 새 인스턴스를 초기화합니다.

ActionBlock<TInput>(Func<TInput,Task>, ExecutionDataflowBlockOptions)

지정된 작업 및 구성 옵션을 사용하여 ActionBlock<TInput> 클래스의 새 인스턴스를 초기화합니다.

ActionBlock<TInput>(Action<TInput>)

지정한 동작을 사용하여 ActionBlock<TInput> 클래스의 새 인스턴스를 초기화합니다.

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))

매개 변수

action
Action<TInput>

수신하는 각 데이터 요소를 사용하여 호출할 작업입니다.

예외

action이(가) null인 경우

적용 대상

ActionBlock<TInput>(Func<TInput,Task>)

지정한 동작을 사용하여 ActionBlock<TInput> 클래스의 새 인스턴스를 초기화합니다.

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))

매개 변수

action
Func<TInput,Task>

수신하는 각 데이터 요소를 사용하여 호출할 작업입니다.

예외

action이(가) null인 경우

적용 대상

ActionBlock<TInput>(Action<TInput>, ExecutionDataflowBlockOptions)

지정된 작업 및 구성 옵션을 사용하여 ActionBlock<TInput> 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

action
Action<TInput>

수신하는 각 데이터 요소를 사용하여 호출할 작업입니다.

dataflowBlockOptions
ExecutionDataflowBlockOptions

ActionBlock<TInput>을 구성하는 옵션입니다.

예외

action이(가) null인 경우

또는 dataflowBlockOptions이(가) null인 경우

예제

다음 예제에서는 생성자를 사용하여 ActionBlock<TInput>(Action<TInput>, ExecutionDataflowBlockOptions)ActionBlock<TInput> 개체를 만드는 방법을 보여줍니다. 이 코드 예제는 방법: 데이터 흐름 블록 토픽에서 병렬 처리 수준 지정에 제공된 더 큰 예제의 일부입니다.

// 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

적용 대상

ActionBlock<TInput>(Func<TInput,Task>, ExecutionDataflowBlockOptions)

지정된 작업 및 구성 옵션을 사용하여 ActionBlock<TInput> 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

action
Func<TInput,Task>

수신하는 각 데이터 요소를 사용하여 호출할 작업입니다.

dataflowBlockOptions
ExecutionDataflowBlockOptions

ActionBlock<TInput>을 구성하는 옵션입니다.

예외

action이(가) null인 경우

또는 dataflowBlockOptions이(가) null인 경우

적용 대상