Your question doesn't include many details, so the following is just a guess of what you might need.
I think the simplest way to do this is to have two ActionBlock
s, running on different priorities on QueuedTaskScheduler
from ParallelExtensionsExtras. You would link to the high-priority one using a predicate and then to the low-priority one. Also, to make sure high-priority Task
s aren't waiting, set MaxMessagesPerTask
of the low-priority block.
In code, it would look something like:
static ITargetBlock<T> CreatePrioritizedActionBlock<T>(
Action<T> action, Predicate<T> isPrioritizedPredicate)
{
var buffer = new BufferBlock<T>();
var scheduler = new QueuedTaskScheduler(1);
var highPriorityScheduler = scheduler.ActivateNewQueue(0);
var lowPriorityScheduler = scheduler.ActivateNewQueue(1);
var highPriorityBlock = new ActionBlock<T>(
action, new ExecutionDataflowBlockOptions
{
TaskScheduler = highPriorityScheduler
});
var lowPriorityBlock = new ActionBlock<T>(
action, new ExecutionDataflowBlockOptions
{
TaskScheduler = lowPriorityScheduler,
MaxMessagesPerTask = 1
});
buffer.LinkTo(highPriorityBlock, isPrioritizedPredicate);
buffer.LinkTo(lowPriorityBlock);
return buffer;
}
This is just a sketch of what you could do, for example, Completion
of the returned block doesn't behave correctly.