Getting MVC mini-profiler timings into async tasks

前端 未结 2 468
心在旅途
心在旅途 2020-12-30 13:36

I have a long running SQL query inside a page that I\'ve sped up by using an async task:

using System.Threading.Tasks;
...

var asyncTask = new Task

        
2条回答
  •  时光说笑
    2020-12-30 14:03

    What you can do is to create a new profiler and attach it to the web one.

    var newProfiler = new MiniProfiler("- Other task (discard this time)", ProfileLevel.Verbose);
    MiniProfiler.Current.AddProfilerResults(newProfiler);
    
    var asyncTask = new Task(() =>
    {
        using (newProfiler.Step("Async!"))
        {
            Thread.Sleep(500);
            using (newProfiler.Step("Async 2!"))
            {
                Thread.Sleep(1000);
            }
        }
    });
    
    asyncTask.Start();
    

    The new profiler will have wrong times in its declaration but the steps are gonna be ok.

提交回复
热议问题