title: Best .net 4.5 async method to know when multiple conditional tasks complete?
body: <p>I have a function that extracts values from an email header. To speed things up, wanted to use the async from framework 4.5. This is my first attempt to use async.</p>
  
  <p>I am calling the extracting function asynchronously several times in succession to pull different values. From an email header. What I am having trouble with is how to know when all instances have completed. I found examples but none that fit my situation with conditional tasks. </p>
  
  <p>I believe I need to:</p>
  
  <ul>
  <li>Dim a task array</li>
  <li>Add each necessary task to the array</li>
  <li>Afterward, use Task.WhenAll</li>
  </ul>
  
  <p>But, I am not sure how to do it.</p>
  
  <pre><code>            'Extract these vars from header if no value was passed
              'Calling HeaderExtract Async for speed
              If Len(sClient) = 0 Then
                  sClient = HeaderExtractAsync("Client,", sHeaders).Result
     ' --&gt; Add this as a new task?
              End If
              If Len(sSubscriptionNum) = 0 Then
                  sSubscriptionNum = HeaderExtractAsync("SubscriptionNum,", sHeaders).Result
              End If
              If Len(sTargetID) = 0 Then
                  sTargetID = HeaderExtractAsync("TargetID,", sHeaders).Result
              End If
              If Len(sAddressBook) = 0 Then
                  sAddressBook = HeaderExtractAsync("AddressBook,", strHeaders).Result
              End If
  
  ' --&gt; Check that all are done?
  </code></pre>