title: TPL : one or more error occured
body: <p>Environment : C#, VS2010, .NET 4.0</p>
  
  <p>I have error message below. However, If I try to run one more, then it works. I'm going to check why it works like this. Would you please any comment ? </p>
  
  <ul>
  <li>Run application program.</li>
  <li>Execute tplTest method.</li>
  <li>occur Error</li>
  <li>Execute tplTest method.</li>
  <li>it works.</li>
  </ul>
  
  <p><strong>Error message :</strong></p>
  
  <p>[9008] Error Form1::tplTest Error: MESASGE[one or more error occurred.]<br>
  [9008] SOURCE[mscorlib]<br>
  [9008] TRACE[Location: System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)</p>
  
  <p><em><strong></em> Code Snippet :</strong></p>
  
  <pre><code>private void tplTest(List&lt;string&gt; listFileNames)
        {
            try
            {
                var exceptions = new ConcurrentQueue&lt;Exception&gt;();
  
                List&lt;Task&lt;TResult&gt;&gt; tasks = new List&lt;Task&lt;TResult&gt;&gt;();
  
                foreach (string item in listFileNames)
                {
                    Task&lt;TResult&gt; t_MethodA = Task.Factory.StartNew&lt;TResult&gt;(tpSharpness, item);
                    tasks.Add(t_MethodA);
                }
  
                try
                {
                    Task.WaitAll(tasks.ToArray()); // &lt;-- Error Occurred
  
                    foreach (Task&lt;TResult&gt; item in tasks)
                    {
                        if (item.IsCompleted)
                        {
                            TResult _result = item.Result;
              // TODO Something
                            //...
                        }
                    }
                }
                catch (Exception e)
                {
                    exceptions.Enqueue(e);
                }
  
                if (exceptions.Count &gt; 0)
                    throw new AggregateException(exceptions);              
            }
            catch (AggregateException exception)
            {
                foreach (Exception ex in exception.InnerExceptions)
                    log.AddErrorLog(this.Name, MethodBase.GetCurrentMethod().Name, string.Format("Error: MESASGE[{0}]\r\nSOURCE[{1}]\r\nTRACE[{2}]", ex.Message, ex.Source, ex.StackTrace));
            }
        }
  
       private TResult tpSharpness(object arg)
        {
            SharpnessTask _tpSharp = new SharpnessTask();
            return _tpSharp.Task();
        }
  </code></pre>