Async await in linq select
<p>I need to modify an existing program and it contains following code:</p>

<pre><code>var inputs = events.Select(async ev =&gt; await ProcessEventAsync(ev))
                   .Select(t =&gt; t.Result)
                   .Where(i =&gt; i != null)
                   .ToList();
</code></pre>

<p>But this seems very weird to me, first of all the use of <code>async</code> and <code>await</code>in the select. According to <a href="https://stackoverflow.com/a/23113336/3410196">this answer</a> by Stephen Cleary I should be able to drop those. </p>

<p>Then the second <code>Select</code> which selects the result. Doesn't this mean the task isn't async at all and is performed synchronously (so much effort for nothing), or will the task be performed asynchronously and when it's done the rest of the query is executed?</p>

<p>Should I write the above code like following according to <a href="https://stackoverflow.com/a/21868161/3410196">another answer by Stephen Cleary</a>:</p>

<pre><code>var tasks = await Task.WhenAll(events.Select(ev =&gt; ProcessEventAsync(ev)));
var inputs = tasks.Where(result =&gt; result != null).ToList();
</code></pre>

<p>and is it completely the same like this?</p>

<pre><code>var inputs = (await Task.WhenAll(events.Select(ev =&gt; ProcessEventAsync(ev))))
                                       .Where(result =&gt; result != null).ToList();
</code></pre>

<p>While i'm working on this project I'd like to change the first code sample but I'm not too keen on changing (apparantly working) async code. Maybe I'm just worrying for nothing and all 3 code samples do exactly the same thing?</p>

<p>ProcessEventsAsync looks like this:</p>

<pre><code>async Task&lt;InputResult&gt; ProcessEventAsync(InputEvent ev) {...}
</code></pre>