Note that there are some explanatory texts on larger screens.

plurals
  1. POTask.Wait in ContinueWhenAll Action
    primarykey
    data
    text
    <p>I was working on encorperating threads into my azure code for putting things on a queue. to do this i used <a href="http://www.microsoft.com/download/en/details.aspx?id=19222" rel="nofollow">http://www.microsoft.com/download/en/details.aspx?id=19222</a> as a reference. </p> <p>my code to enqueue multiple messages looks like this:</p> <pre><code>public void AddMessagesAsync(IEnumerable&lt;IQueueMessage&gt; messages, string queue = null, TimeSpan? timeToLive = null) { //check if we need to switch queues if (!String.IsNullOrEmpty(queue)) { SetCurrent(queue); } //setup list of messages to enqueue var tasks = new List&lt;Task&gt;(); Parallel.ForEach(messages, current =&gt; { if (timeToLive.HasValue) { //create task with TPL var task = Task.Factory.FromAsync(Current.BeginAddMessage, Current.EndAddMessage, Convert(current), timeToLive.Value, tasks); //setup continuation to trigger eventhandler tasks.Add(task.ContinueWith((t) =&gt; AddMessageCompleted(t))); } else { //create task with TPL var task = Task.Factory.FromAsync(Current.BeginAddMessage, Current.EndAddMessage, Convert(current), tasks); //setup continuation to trigger eventhandler tasks.Add(task.ContinueWith((t) =&gt; AddMessageCompleted(t))); } }); //setup handler to trigger when all messages are enqueued, a we are blocking the thread over there to wait for all the threads to complete Task.Factory.ContinueWhenAll(tasks.ToArray(), (t) =&gt; AddMessagesCompleted(t)); } private void AddMessagesCompleted(Task[] tasks) { try { //wait for all tasks to complete Task.WaitAll(tasks); } catch (AggregateException e) { //log the exception var ex = e; //return ex; } if (AddedMessages != null) { AddedMessages(tasks, EventArgs.Empty); } } </code></pre> <p>Now my question is about the Task.Wait in the continuation (which is according to the document provided by MS). it seems a bit strange to wait for threads where you already know the have completed right? the only reason i can imagine is to bubble the errors and process those. am i missing something here?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload