MiniProfiler .Ignore() 扩展方法不会禁用分析

MiniProfiler .Ignore() extension method does not disable profiling

我有一个方法,其中有一部分代码我想在使用 MiniProfiler 时从分析中忽略。

根据文档,执行此操作的扩展方法是 .Ignore(),在 using 语句中使用时应在持续时间内禁用分析。

很遗憾,我没有得到预期的结果。假设我有这个方法结构:

public async Task<IActionResult> FirstMethod()
{
    using (MiniProfiler.Current.Step("FirstMethod"))
    {
        IActionResult result = this.SecondMethod();
        
        using (MiniProfiler.Current.Ignore())
        {
            Thread.Sleep(100); 
        }

        return result;
    }
}

internal virtual IActionResult SecondMethod()
{
    using (MiniProfiler.Current.CustomTiming("SQL", "QuerySecondMethod"))
    {
        // Some data logic
    }
}

我期望的是,在探查器上 FirstMethod 步骤持续时间和 SecondMethod 自定义时间大致相同,因为 FirstMethod 仅调用 SecondMethod 并且是忽略 Thread.Sleep().

但我一直了解到 FirstMethod 持续时间比 SecondMethod 长 100 毫秒,这使得 Ignore 似乎并没有真正禁用其中代码的探查器。

我做错了什么?我是否误解了 Ignore 方法的文档和用途?

.Ignore()方法是抑制里面的代码,不是整体

如果您想停止并丢弃分析器,您的选择是:

MiniProfiler.Current.Stop(discardResults: true);

更多详情,您可以check this issue在github。