Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ol> <li>Your definition of <code>BuildUserFilePath</code> and its usage are inconsistent. The definition clearly states that it's a <code>string</code>-returning method, whereas its usage implies that it returns a <code>Task&lt;&gt;</code>.</li> <li>Parallel.ForEach and async don't mix very well - that's the reason your bug happened in the first place.</li> <li>Unrelated but still worth noting: your <code>try/catch</code> is redundant as all it does is rethrow the original <code>SqlException</code> (and even that it doesn't do very well because you'll end up losing the stack trace).</li> <li><p>Do you really, <em>really</em> want to return <code>null</code>?</p> <pre><code>public async static Task&lt;List&lt;uspGetEmployees_Result&gt;&gt; GetEmployess(int professionalID, int startIndex, int pageSize, string where, string equals) { var httpCurrent = HttpContext.Current; // Most of these operations are unlikely to be time-consuming, // so why await the whole thing? using (AFCCInc_ComEntities db = new AFCCInc_ComEntities()) { // I don't really know what exactly uspGetEmployees returns // and, if it's an IEnumerable, whether it yields its elements lazily. // The fact that it can be null, however, bothers me, so I'll sidestep it. List&lt;uspGetEmployees_Result&gt; emps = await Task.Run(() =&gt; (db.uspGetEmployees(professionalID, startIndex, pageSize, where, equals) ?? Enumerable.Empty&lt;uspGetEmployees_Result&gt;()).ToList() ); // I'm assuming that BuildUserFilePath returns string - no async. await Task.Run(() =&gt; { Parallel.ForEach(emps, e =&gt; { // NO async/await within the ForEach delegate body. e.Avatar = BuildUserFilePath(e.Avatar, e.UserId, httpCurrent, true); }); }); } } </code></pre></li> </ol>
 

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