本文整理汇总了C#中Microsoft.AspNet.Http.HttpContext.GetProfiler方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContext.GetProfiler方法的具体用法?C# HttpContext.GetProfiler怎么用?C# HttpContext.GetProfiler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNet.Http.HttpContext
的用法示例。
在下文中一共展示了HttpContext.GetProfiler方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public async Task Invoke(HttpContext context)
{
// resolve Profiler right away
var profiler = context.GetProfiler();
await _next.Invoke(context);
profiler.Stop();
context.Response.Headers.Add("X-Profiler-Id", profiler.Id.ToString());
profiler.Printout();
}
示例2: SomeWork
private async Task SomeWork(HttpContext context)
{
using (context.GetProfiler().Step("SOMETHING TO DO BEFORE"))
await Task.Delay(TimeSpan.FromMilliseconds(R.NextDouble() * 150 + 50));
using (context.GetProfiler().Step("SOME WORK"))
{
await context.Response.WriteAsync("<ul>");
for (int i = 1; i <= 5; i++)
{
using (context.GetProfiler().Step("RENDER <LI>"))
{
await Task.Delay(TimeSpan.FromMilliseconds(R.NextDouble() * 150 + 50));
await context.Response.WriteAsync($"<li>Item #{i}</li>");
}
}
}
using (context.GetProfiler().Step("SOMETHING TO DO AFTER"))
await Task.Delay(TimeSpan.FromMilliseconds(R.NextDouble() * 150 + 50));
await context.Response.WriteAsync("</ul>");
}
示例3: WaitForExactDelays
private async Task WaitForExactDelays(HttpContext context, string title, TimeSpan delay1, TimeSpan delay2)
{
using (context.GetProfiler().Step($"TITLE: '{title}', CONTAINER"))
{
using (context.GetProfiler().Step($"TITLE: '{title}', First delay"))
{
await Task.Delay(delay1);
}
using (context.GetProfiler().Step($"TITLE: '{title}', Second delay"))
{
await Task.Delay(delay2);
}
}
}
示例4: GetSomeRandomTextWithDelays
private async Task<string> GetSomeRandomTextWithDelays(HttpContext context, string input)
{
using (context.GetProfiler().Step($"CALCULATING STRING OF '{input}'"))
{
await Task.Delay(TimeSpan.FromMilliseconds(R.NextDouble() * 1500 + 100));
var result = $"String '{input}' has lengths of {input.Length} characters.";
_logger.LogInformation($"Results for '{input}' are ready, but we need to wait more");
await Task.Delay(TimeSpan.FromMilliseconds(R.NextDouble() * 1500 + 100));
return result;
}
}