ActionBlock<TInput> 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
받은 모든 데이터 요소에 대해 제공된 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
생성자
| 속성 | Description |
|---|---|
| ActionBlock<TInput>(Action<TInput>, ExecutionDataflowBlockOptions) |
지정된 작업 및 구성 옵션을 사용하여 클래스의 ActionBlock<TInput> 새 인스턴스를 초기화합니다. |
| ActionBlock<TInput>(Action<TInput>) |
지정된 작업을 사용하여 클래스의 ActionBlock<TInput> 새 인스턴스를 초기화합니다. |
| ActionBlock<TInput>(Func<TInput,Task>, ExecutionDataflowBlockOptions) |
지정된 작업 및 구성 옵션을 사용하여 클래스의 ActionBlock<TInput> 새 인스턴스를 초기화합니다. |
| ActionBlock<TInput>(Func<TInput,Task>) |
지정된 작업을 사용하여 클래스의 ActionBlock<TInput> 새 인스턴스를 초기화합니다. |
속성
| 속성 | Description |
|---|---|
| Completion |
Task 데이터 흐름 블록의 비동기 작업 및 완료를 나타내는 개체를 가져옵니다. |
| InputCount |
이 블록에서 처리될 때까지 대기 중인 입력 항목의 수를 가져옵니다. |
메서드
| 속성 | Description |
|---|---|
| Complete() |
데이터 흐름 블록에 더 이상 메시지를 수락하거나 생성해서는 안 되며 더 이상 연기된 메시지를 사용해서는 안 됨을 알 수 있습니다. |
| Equals(Object) |
지정된 개체가 현재 개체와 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
| GetHashCode() |
기본 해시 함수로 사용됩니다. (다음에서 상속됨 Object) |
| GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| Post(TInput) |
대상 데이터 흐름 블록에 항목을 게시합니다. |
| ToString() |
이 IDataflowBlock 인스턴스의 서식이 지정된 이름을 나타내는 문자열을 반환합니다. |
명시적 인터페이스 구현
| 속성 | Description |
|---|---|
| IDataflowBlock.Fault(Exception) |
데이터 흐름 블록이 오류 상태로 완료되도록 합니다. |
| ITargetBlock<TInput>.OfferMessage(DataflowMessageHeader, TInput, ISourceBlock<TInput>, Boolean) |
데이터 흐름 블록에 메시지를 제공하고 메시지를 사용하거나 연기할 수 있는 기회를 제공합니다. |
확장명 메서드
| 속성 | Description |
|---|---|
| AsObserver<TInput>(ITargetBlock<TInput>) |
에 대한 새 IObserver<T> 추상화 만들기 ITargetBlock<TInput> |
| Post<TInput>(ITargetBlock<TInput>, TInput) |
에 항목을 게시합니다 ITargetBlock<TInput>. |
| SendAsync<TInput>(ITargetBlock<TInput>, TInput, CancellationToken) |
대상 메시지 블록에 메시지를 비동기적으로 제공하여 연기할 수 있습니다. |
| SendAsync<TInput>(ITargetBlock<TInput>, TInput) |
대상 메시지 블록에 메시지를 비동기적으로 제공하여 연기할 수 있습니다. |