title: TPL Dataflow block which delays the forward of the message to the next block
body: <p>I require a Dataflow block which delays the forward of the message to the next block based on the timestamp in the message (LogEntry).</p>
  
  <p>This is what i came up with but it feels not right. Any suggestions for improvements?</p>
  
  <pre><code>  private IPropagatorBlock&lt;LogEntry, LogEntry&gt; DelayedForwardBlock()
      {
          var buffer = new ConcurrentQueue&lt;LogEntry&gt;();
  
          var source = new BufferBlock&lt;LogEntry&gt;();
  
          var target = new ActionBlock&lt;LogEntry&gt;(item =&gt;
          {
              buffer.Enqueue(item);
          });
  
  
          Task.Run(() =&gt;
              {
                  LogEntry entry;
                  while (true)
                  {
                      entry = null;
                      if (buffer.TryPeek(out entry))
                      {
                          if (entry.UtcTimestamp &lt; (DateTime.UtcNow - TimeSpan.FromMinutes(5)))
                          {
                              buffer.TryDequeue(out entry);
                              source.Post(entry);
                          }
                      }
                  }
              });
  
  
          target.Completion.ContinueWith(delegate
          {
              LogEntry entry;
              while (buffer.TryDequeue(out entry))
              {
                  source.Post(entry);
              }
  
              source.Complete();
          });
  
          return DataflowBlock.Encapsulate(target, source);
      }
  </code></pre>