title: why this exception is coming : One or more errors occurred. at System.Threading.Tasks.Task.ThrowIfExceptional
body: <p>I am developing a task scheduler where I am fetching data from more than 200 queries and running these queries in Parallel.foreach loop.
  But I am getting the below error:</p>
  
  <blockquote>
    <p>One or more errors occurred. at
    System.Threading.Tasks.Task.ThrowIfExceptional(Boolean
    includeTaskCanceledExceptions) at
    System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout,
    CancellationToken cancellationToken) at
    System.Threading.Tasks.Task.Wait() at
    System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive,
    Int32 toExclusive, ParallelOptions parallelOptions, Action<code>1 body,
    Action</code>2 bodyWithState, Func<code>4 bodyWithLocal, Func</code>1 localInit,
    Action<code>1 localFinally) at
    System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IList</code>1
    list, ParallelOptions parallelOptions, Action<code>1 body, Action</code>2
    bodyWithState, Action<code>3 bodyWithStateAndIndex, Func</code>4
    bodyWithStateAndLocal, Func<code>5 bodyWithEverything, Func</code>1 localInit,
    Action<code>1 localFinally) at
    System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable</code>1
    source, ParallelOptions parallelOptions, Action<code>1 body, Action</code>2
    bodyWithState, Action<code>3 bodyWithStateAndIndex, Func</code>4
    bodyWithStateAndLocal, Func<code>5 bodyWithEverything, Func</code>1 localInit,
    Action<code>1 localFinally) at
    System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable</code>1 source,
    Action`1 body) at PFMSAccountJob.JobMethods.AppService.runService() in
    C:\SVN\PFMSToPFG_RAWDbJob\PFMSToPFG_RAWDbJob\JobMethods\AppService.cs:line
    95 Void ThrowIfExceptional(Boolean)</p>
  </blockquote>
  
  <p>I have tried with Cancellation token and Cancellation token source but still getting the same issue.</p>
  
  <pre><code> Parallel.ForEach(queries, query =&gt;
                           {
  
                             qry = query.Replace(Convert.ToString("TmpOblId"), val);
                               dt = DBUtil.ExecSelectMultipleSQL(accIdqryConnNode.ToString(), qry);
  
                               DataTable dtCopy = dt.Copy();
                               ds.Tables.Add(dtCopy);
  
  
                           });
  </code></pre>
  
  <p>Kindly help with this issue. As whenever I am getting this issue the task scheduler gets terminated automatically</p>