title: How to wait for key to be added to collection
body: <p>I would like to find a clean way for a thread to wait until a key is found in a collection (knowing for sure that it will happen at some point)</p>
  
  <p>For some context, I have a list of items that need to be validated. The dictionary will contain the item Id as key and a bool as value.
  These items aren't in a flat list however. Item are linked as being next after a previous item (many to many). An item can be followed by and/or preceded by multiple items. There could also be multiple start points. No loops though.</p>
  
  <p>A item will only be validated if all it's previous items are also validated.
  Because of the many to many relation between items, it is very possible that an item will get checked twice. This is why I create a new list just containing all items that are validated or being validated (called seen items later on).</p>
  
  <p><strong>An example :</strong></p>
  
  <pre><code>   Item1 -- &gt; Item3 --&gt; Item4 -- &gt; Item6
            /                    /
     Item2 /  ----------&gt; Item5 /
  </code></pre>
  
  <p>I start at item6, add it to the seen items, then parallel check all previous items (4,5). Item5 will then check item2. Item4 will then check 3, 2 and 1. Item2 will get checked twice now. 
  To counter this, the thread will first check if item2 is already in the seen items, and if so, get the value from the result dictionary instead of checking again.</p>
  
  <p><strong>Problem:</strong> </p>
  
  <p>When a thread that needs to check item2 finds item2 in the seen items, it doesn't know the value yet. The value might not be calculated yet because a different thread is still busy checked it.
  How would I order this thread to wait for this item to be added to the result dictionary and once it is added, get it's value, and proceed normally?
  (I know for sure it will at some point be added)</p>
  
  <p>(A bit of not 100% understanding multi threading nonsense next) <br>
  It would of course be nice if the thread that is stuck waiting could be used somewhere else to check items that are not yet being checked, if that makes sense.</p>
  
  <p><strong>The code:</strong></p>
  
  <pre><code>// Item not yet checked
  if (alreadySeenActions.TryAdd(item.Id, item.Id))
  {
     // Check the childs 
     var childsAreValid = CheckChilds(item);
     result.Add(item.Id, childsAreValid);
  
     // Do some more 
  // Item already checked/being checked
  } else {
      // item.Id might not be in the result yet, but it will always be (otherwise it will never end up in the alreadySeenActions in the first place and not enter this else)
      // So what do I write here?
      var value = result[item.Id]
  
      if(value)
      // Do some more
  }
  </code></pre>