我有一個方法,其中包含在使用 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持續時間比 100 毫秒長SecondMethod,這使得它看起來Ignore并沒有真正禁用其中代碼的探查器。
我究竟做錯了什么?我是否誤解了該Ignore方法的檔案和目的?
uj5u.com熱心網友回復:
該.Ignore()方法是為了抑制其中的代碼,而不是整體。
如果您想停止并丟棄分析器,您的選擇是:
MiniProfiler.Current.Stop(discardResults: true);
有關更多詳細資訊,您可以在 github中查看此問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/425442.html
