private void HandleEndRequest(object sender, EventArgs e) { var duration = (float)_timer.ElapsedTicks / Stopwatch.Frequency; HttpContext.Current.Response.Write( $"<div style='color:red;'>TimerModule:</br>" + $"Время обработки запроса: {duration:F5} секунд" + $"</div>"); RequestTimed?.Invoke(this, new RequestTimerEventArgs { Duration = duration }); }
public void Init(HttpApplication application) { application.BeginRequest += (src, args) => { this.timer = Stopwatch.StartNew(); }; application.EndRequest += (src, args) => { var eventArgs = new RequestTimeEventArgs { DurationMilliseconds = this.timer.ElapsedMilliseconds }; RequestTimed?.Invoke(this, eventArgs); }; }
private void HandleEvent(object src, EventArgs args) { HttpContext ctx = HttpContext.Current; if (ctx.CurrentNotification == RequestNotification.BeginRequest) { timer = Stopwatch.StartNew(); } else { float duration = ((float)timer.ElapsedTicks) / Stopwatch.Frequency; ctx.Response.Write( string.Format( "<div class='alert alert-success'>Elapsed:{0:F5} seconds</div>", ((float)timer.ElapsedTicks) / Stopwatch.Frequency)); RequestTimed?.Invoke(this, new RequestTimerEventArgs { Duration = duration }); } }