title: Wait For Asynchronous Events to Finish in Foreach
body: <p>How can I send a request to server using foreach and when i get response then for foreach wait for the returned information to process before continuing on to the next request.</p>
  
  <p>My problem: in foreach I send many requests and foreach continues without process with information which i get in response.</p>
  
  <p>For example:</p>
  
  <pre><code>foreach (DataLoader.GetInfo items in listBoxFetInfo.Items)
  {  
      DownloadInfo(items.CompanyName);                     
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>void DownloadInfo(string name)
  {
     int requestId = feed.SendCompanyNameRequest(symbol.ToUpper(), sendType, sendTimePeriod, sendDateFrom, DateTime.Now);
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>feed.RequestCompanyName += new IFeedEvents_RequestCompanyNameEventHandler(feed_RequestName);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>void feed_RequestName(int originalRequestId, short ResponseCode, string symbol, short symbolStatusCode, object records)
  {
  //save to file
  }
  </code></pre>
  
  <p>I can't use <a href="https://msdn.microsoft.com/en-AU/library/jj155756.aspx" rel="nofollow">Start Multiple Async Tasks and Process Them As They Complete </a> because this solution need in add CancellationToken where i can not add (can not in void feed_RequestName</p>
  
  <p>What another solution can be in this problem?</p>
  
  <p>Also, i can not change signature of:</p>
  
  <pre><code>feed_RequestName(int originalRequestId, short ResponseCode, string symbol, short symbolStatusCode, object records)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>feed.SendCompanyNameRequest(symbol.ToUpper(), sendType, sendTimePeriod, sendDateFrom, DateTime.Now);
  </code></pre>