title: Set Timeout for item in Parallel.ForEach
body: <p>I'm using Parallel.ForEach to process over an concurrent dictionary collection. ConcurrentDictionary contains Key and Byte field.</p>
  
  <p>concurrentDictionary - is Concurrent Dictionary collection here.</p>
  
  <pre><code>Parallel.ForEach(concurentDictionary, (item) =&gt;
  {
      var mailObject = dbContext.MailObjects.Where(x=&gt; x.MailObjectId == item.key).Select(y=&gt; y);
      mailObject.MailBody = ConvertToPdf(item.Value.MailBody);
  } 
  dbContext.SaveChanges();
  </code></pre>
  
  <p>I want to set timeout if any particular item takes maximum time set say 60 seconds. If it takes more than 60 sec, I would like to exit and not save that particular item. Rest of the items should be saved by <code>dbContext.SaveChanges()</code> method. How can this be achieved in Parallel.ForEach?</p>