title: C# How to have a generic method do awaiting?
body: <p>Okay, bad title, but I couldn't think of a better name..My question isn't probably even specific to async/await, but my question is coming up during async handling, so I'm going to pose it that way:</p>
  
  <p>I have several methods which create lists of tasks and then do an 'await Task.WhenAll(list of tasks)". The specific kind of tasks being awaited on in these methods varies. For example, some methods are awaiting a list of <code>Task&lt;String&gt;</code>, while others are awaiting a list of <code>Task&lt;foo&gt;</code>.</p>
  
  <p>What I'm finding is that I'm needing to do some non-trivial try/catch processing around the Task.WhenAll() in each of these methods, and that code is always the same. I'd like to move that code to a common method, and then pass in the list of tasks and have that common method issue then WhenAll, wrapped up in the try/finally. </p>
  
  <p>But the problem I'm running in to is that each of the methods calling this method will be passing in lists of different Task types, and this causes a compiler complain when I declare the parameter to my common method as just Task:</p>
  
  <pre><code>methodA:
      List&lt;Task&lt;String&gt;&gt; myTaskList = ...
      ExecuteTasks(myTaskList);
  
  methodB:
      List&lt;Task&lt;Foo&gt;&gt; myTaskList = ...
      ExecuteTasks(myTaskList);
  
   async Task ExecuteTasks(List&lt;Task&gt; taskList) {
      try {
          await Task.WhenAll(taskList)
          }
      catch {
          ..common catch handling goes here. This handling isn't really sensitive to the
          ..type of the Tasks, we just need to examine it's Status and Exception properties..
          }
      }
  </code></pre>
  
  <p>In the above, methodA and methodB each have their own kinds of task lists that need to be passed in to ExecuteTasks, but the question is how to define the list of tasks to ExecuteTasks so that the compiler doesn't complain about type mismatches?  In a non-generic world, I would probably define the parameter to ExecuteTasks a super-class of the the types of list of methodA and methodB so the compiler could "upcast" them, but this approach doesn't seem to work here.. (I tried defining ExecuteTasks as taking a <code>Task&lt;Object&gt;</code> but that didn't solve the type mismatch problem)</p>