c# wait for a task inside a loop
<p>I'm using TPL in a Windows Form Application in the following way: </p>

<pre><code>foreach (var item in items)
{
    task = Task&lt;object&gt;.Factory.StartNew (() =&gt; doWork());
    task.Wait();
    //update the UI using the result
}
</code></pre>

<p>I am waiting for the task to finish, because I need to process every item in the list, but as you imagine this is causing a lock in my UI thread (the UI freezes).</p>

<p>I'd like to know how can I implement this in a way that does not lock the UI thread. </p>

<p><strong>Update</strong>: I'm using .NET Framework 4.5</p>

<p>Thanks. </p>

<p>P.S DoWork() is a long run operation. </p>