When posting an item to a TPL DataFlow
, is there any mechanism that can allow for a delayed post?
public partial class BasicDataFlowService
{
private readonly ActionBlock<string> workerBlock;
public BasicDataFlowService()
{
workerBlock = new ActionBlock<string>(file => DoWork(file), new ExecutionDataflowBlockOptions()
{
MaxDegreeOfParallelism = 32
});
}
partial void DoWork(string fileName);
private void AddToDataFlow(string file)
{
workerBlock.Post(file);
}
}
Within AddToDataFlow
, I would like to be able to specify a delay before the item is processed (e.g. if we've decided we want to defer the processing for 30 seconds).
I did consider using a TransFormBlock
with new System.Threading.ManualResetEvent(false).WaitOne(1000);
, e.g.
var requeueBlock = new TransformBlock<string, string>(file =>
{
new System.Threading.ManualResetEvent(false).WaitOne(1000);
return file;
});
requeueBlock.LinkTo(workerBlock);
However, this would appear to be consuming a thread needlessly that could be used by other blocks in the chain.