Export (0) Print
Expand All

ConcurrentExclusiveSchedulerPair Class

.NET Framework 4.5

Provides task schedulers that coordinate to execute tasks while ensuring that concurrent tasks may run concurrently and exclusive tasks never do.

System.Object
  System.Threading.Tasks.ConcurrentExclusiveSchedulerPair

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

[HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true, 
	ExternalThreading = true)]
public class ConcurrentExclusiveSchedulerPair

The ConcurrentExclusiveSchedulerPair type exposes the following members.

  NameDescription
Public methodSupported in .NET for Windows Store appsConcurrentExclusiveSchedulerPair()Initializes a new instance of the ConcurrentExclusiveSchedulerPair class.
Public methodSupported in .NET for Windows Store appsConcurrentExclusiveSchedulerPair(TaskScheduler)Initializes a new instance of the ConcurrentExclusiveSchedulerPair class that targets the specified scheduler.
Public methodSupported in .NET for Windows Store appsConcurrentExclusiveSchedulerPair(TaskScheduler, Int32)Initializes a new instance of the ConcurrentExclusiveSchedulerPair class that targets the specified scheduler with a maximum concurrency level.
Public methodSupported in .NET for Windows Store appsConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32)Initializes a new instance of the ConcurrentExclusiveSchedulerPair class that targets the specified scheduler with a maximum concurrency level and a maximum number of scheduled tasks that may be processed as a unit.
Top

  NameDescription
Public propertySupported in .NET for Windows Store appsCompletionGets a Task that will complete when the scheduler has completed processing.
Public propertySupported in .NET for Windows Store appsConcurrentSchedulerGets a TaskScheduler that can be used to schedule tasks to this pair that may run concurrently with other tasks on this pair.
Public propertySupported in .NET for Windows Store appsExclusiveSchedulerGets a TaskScheduler that can be used to schedule tasks to this pair that must run exclusively with regards to other tasks on this pair.
Top

  NameDescription
Public methodSupported in .NET for Windows Store appsCompleteInforms the scheduler pair that it should not accept any more tasks.
Public methodSupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top

NoteNote

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: Synchronization | ExternalThreading. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

The following example shows the use of the ConcurrentExclusiveSchedulerPair class. Readers run on the concurrent part of the scheduler. The writer runs on the exclusive part of the scheduler. This code example is part of a larger example provided for the How to: Specify a Task Scheduler in a Dataflow Block topic.

// Create a ConcurrentExclusiveSchedulerPair object. 
// Readers will run on the concurrent part of the scheduler pair. 
// The writer will run on the exclusive part of the scheduler pair. 
var taskSchedulerPair = new ConcurrentExclusiveSchedulerPair();

// Create an ActionBlock<int> object for each reader CheckBox object. 
// Each ActionBlock<int> object represents an action that can read  
// from a resource in parallel to other readers. 
// Specifying the concurrent part of the scheduler pair enables the  
// reader to run in parallel to other actions that are managed by  
// that scheduler. 
var readerActions = 
   from checkBox in new CheckBox[] {checkBox1, checkBox2, checkBox3}
   select new ActionBlock<int>(milliseconds =>
   {
      // Toggle the check box to the checked state.
      toggleCheckBox.Post(checkBox);

      // Perform the read action. For demonstration, suspend the current 
      // thread to simulate a lengthy read operation.
      Thread.Sleep(milliseconds);

      // Toggle the check box to the unchecked state.
      toggleCheckBox.Post(checkBox);
   },
   new ExecutionDataflowBlockOptions
   {
      TaskScheduler = taskSchedulerPair.ConcurrentScheduler
   });

// Create an ActionBlock<int> object for the writer CheckBox object. 
// This ActionBlock<int> object represents an action that writes to  
// a resource, but cannot run in parallel to readers. 
// Specifying the exclusive part of the scheduler pair enables the  
// writer to run in exclusively with respect to other actions that are  
// managed by the scheduler pair. 
var writerAction = new ActionBlock<int>(milliseconds =>
{
   // Toggle the check box to the checked state.
   toggleCheckBox.Post(checkBox4);

   // Perform the write action. For demonstration, suspend the current 
   // thread to simulate a lengthy write operation.
   Thread.Sleep(milliseconds);

   // Toggle the check box to the unchecked state.
   toggleCheckBox.Post(checkBox4);
},
new ExecutionDataflowBlockOptions
{
   TaskScheduler = taskSchedulerPair.ExclusiveScheduler
});

// Link the broadcaster to each reader and writer block. 
// The BroadcastBlock<T> class propagates values that it  
// receives to all connected targets. 
foreach (var readerAction in readerActions)
{
   broadcaster.LinkTo(readerAction);
}
broadcaster.LinkTo(writerAction);

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, 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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft