Export (0) Print
Expand All

ActionBlock<TInput>.Post Method

.NET Framework 4.5

Posts an item to the target dataflow block.

Namespace:  System.Threading.Tasks.Dataflow
Assembly:  System.Threading.Tasks.Dataflow (in System.Threading.Tasks.Dataflow.dll)

public bool Post(
	TInput item


Type: TInput

The item being offered to the target.

Return Value

Type: System.Boolean
true if the item is posted to the dataflow block; otherwise, false.

The following example shows how to use the Post method to post an item to the target dataflow block. This code example is part of a larger example provided for the 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();

   for (int i = 0; i < messageCount; i++)

   // Wait for all messages to propagate through the network.

   // Stop the timer and return the elapsed number of milliseconds.
   return stopwatch.Elapsed;

.NET Framework

Supported in: 4.5

Portable Class Library

Supported in: Portable Class Library

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft