ActionBlock<TInput> 클래스

정의

수신한 모든 데이터 요소에 대해 제공된 Action<T> 대리자를 호출하는 데이터 흐름 블록을 제공합니다.

generic <typename TInput>
public ref class ActionBlock sealed : System::Threading::Tasks::Dataflow::ITargetBlock<TInput>
public sealed class ActionBlock<TInput> : System.Threading.Tasks.Dataflow.ITargetBlock<TInput>
type ActionBlock<'Input> = class
    interface ITargetBlock<'Input>
    interface IDataflowBlock
type ActionBlock<'Input> = class
    interface IDataflowBlock
    interface ITargetBlock<'Input>
Public NotInheritable Class ActionBlock(Of TInput)
Implements ITargetBlock(Of TInput)

형식 매개 변수

TInput

ActionBlock<TInput>이 수행되는 데이터 형식입니다.

상속
ActionBlock<TInput>
구현

예제

다음 예제에서는 클래스를 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

설명

참고

TPL 데이터 흐름 라이브러리(System.Threading.Tasks.Dataflow 네임스페이스)는 .NET과 함께 배포되지 않습니다. Visual Studio에서 System.Threading.Tasks.Dataflow 네임스페이스를 설치하려면 프로젝트를 열고, 프로젝트 메뉴에서 NuGet 패키지 관리를 선택한 후, System.Threading.Tasks.Dataflow 패키지를 온라인으로 검색합니다. 또는 .NET Core CLI를 사용하여 설치하려면 dotnet add package System.Threading.Tasks.Dataflow를 실행합니다.

생성자

ActionBlock<TInput>(Action<TInput>)

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

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

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

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

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

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

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

속성

Completion

비동기 작업 및 데이터 흐름 블록의 완료를 나타내는 Task 개체를 가져옵니다.

InputCount

이 블록에서 처리되도록 대기 중인 입력 항목의 수를 가져옵니다.

메서드

Complete()

데이터 흐름 블록에 대한 신호를 통해 더 이상의 메시지를 받거나 생성할 수 없으며 추가로 지연된 메시지를 사용하면 안 됩니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Post(TInput)

대상 데이터 흐름 블록에 대한 항목을 게시합니다.

ToString()

IDataflowBlock 인스턴스의 형식 지정된 이름을 나타내는 문자열을 반환합니다.

명시적 인터페이스 구현

IDataflowBlock.Fault(Exception)

오류 상태에서 데이터 흐름 블록이 완료되도록 합니다.

ITargetBlock<TInput>.OfferMessage(DataflowMessageHeader, TInput, ISourceBlock<TInput>, Boolean)

메시지를 데이터 흐름 블록에 제공하며 메시지를 선택적으로 사용하거나 연기할 수 있습니다.

확장 메서드

AsObserver<TInput>(ITargetBlock<TInput>)

ITargetBlock<TInput> 위에 새 IObserver<T> 추상화를 만듭니다.

Post<TInput>(ITargetBlock<TInput>, TInput)

ITargetBlock<TInput>에 항목을 게시합니다.

SendAsync<TInput>(ITargetBlock<TInput>, TInput)

대상 메시지 블록에 메시지를 비동기적으로 제공하며, 연기를 허용합니다.

SendAsync<TInput>(ITargetBlock<TInput>, TInput, CancellationToken)

대상 메시지 블록에 메시지를 비동기적으로 제공하며, 연기를 허용합니다.

적용 대상