title: Avoiding await in foreach loop
body: <p>I am trying to optimize this code to decrease the time taken to complete the <code>for</code>loop. In this case, <code>CreateNotification()</code> takes a long time and using <code>async</code> <code>await</code> does not improve performance as each asynchronous call is being awaited. I would like to use <code>Task.WhenAll()</code> to optimize the code. How can I do this? </p>
  
  <pre><code>foreach (var notification in notificationsInput.Notifications)
  {
    try
    {
      var result = await CreateNotification(notification);
      notification.Result = result;          
    }
    catch (Exception exception)
    {
      notification.Result = null;
    }
    notifications.Add(notification);
  }
  </code></pre>