internal override void OnEndRequest(OwaContext owaContext)
 {
     try
     {
     }
     finally
     {
         UserContext userContext = owaContext.UserContext;
         bool        flag        = false;
         try
         {
             if (owaContext.UserContext != null && !owaContext.UserContext.LockedByCurrentThread())
             {
                 if (!owaContext.IsAsyncRequest && !owaContext.HandledCriticalError && !owaContext.UserContext.LastLockRequestFailed)
                 {
                     ExWatson.SendReport(new InvalidOperationException("Entered OwaRequestEventInspector without the UserContext lock when we should have had it."), ReportOptions.None, null);
                 }
                 owaContext.UserContext.Lock();
             }
             try
             {
                 try
                 {
                     if (userContext != null && userContext.State == UserContextState.Active)
                     {
                         userContext.CleanupOnEndRequest();
                         owaContext.ExitLatencyDetectionContext();
                         OwaPerformanceLogger.LogPerformanceStatistics(userContext);
                         OwaPerformanceLogger.TracePerformance(userContext);
                         this.AppendServerHeaders(owaContext);
                         if (owaContext.SearchPerformanceData != null)
                         {
                             owaContext.SearchPerformanceData.RefreshEnd();
                             owaContext.SearchPerformanceData.WriteLog();
                         }
                     }
                 }
                 finally
                 {
                     owaContext.DisposeObjectsOnEndRequest();
                 }
             }
             catch (OwaLockTimeoutException)
             {
                 flag = true;
             }
             finally
             {
                 if (userContext != null && !flag)
                 {
                     if (owaContext.IgnoreUnlockForcefully)
                     {
                         userContext.Unlock();
                     }
                     else
                     {
                         userContext.UnlockForcefully();
                     }
                 }
             }
         }
         finally
         {
             owaContext.TryReleaseBudgetAndStopTiming();
             if (owaContext.PreFormActionData != null && owaContext.PreFormActionData is IDisposable)
             {
                 ((IDisposable)owaContext.PreFormActionData).Dispose();
                 owaContext.PreFormActionData = null;
             }
         }
     }
 }