Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting MVC mini-profiler timings into async tasks
    text
    copied!<p>I have a long running SQL query inside a page that I've sped up by using an async task:</p> <pre><code>using System.Threading.Tasks; ... var asyncTask = new Task&lt;ResultClass&gt;( () =&gt; { using (var stepAsync = MiniProfiler.Current.Step("Async!")) { // exec long running SQL } }); asyncTask.Start(); // do lots of other slow stuff ResultClass result; using (var stepWait = MiniProfiler.Current.Step("Wait for Async")) { result = asyncTask.Result; } </code></pre> <p>(Note that this syntax will be a lot nicer once C# 5 comes out with <code>async</code> and <code>await</code>)</p> <p>When using MVC mini profiler I get the timing for "Wait for Async", but I can't get the timing for the "Async!" step.</p> <p>Is there any way to get those results (maybe just the SQL timings) into the trace for the completed page?</p> <p><strong>Update</strong></p> <p>I've found a way to get the profiler steps into the async method:</p> <pre><code>var asyncTask = new Task&lt;ResultClass&gt;( profiler =&gt; { using (var step = (profiler as MiniProfiler).Step("Async!")) { // exec long running SQL } }, MiniProfiler.Current); </code></pre> <p>That almost works, in that the "Async!" step appears (somewhat randomly, depending on the execution, and with some times appearing as negative) but isn't really what I want. The SQL timings and statements are still lost, and in this case they're the most valuable information.</p> <p>Ideally I'd like the "Wait for Async" step to be linked to the timings (rather than the start step). Is there some way that <code>stepWait</code> could be linked to the SQL profiler times for the result?</p> <p>Any ideas?</p>
 

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