Esempio n. 1
0
        private static void WatsonThreadProc(object stateInfo)
        {
            Thread.CurrentThread.IsBackground = false;
            DisposeTrackerObject <T> .WatsonThreadStateInfo watsonThreadStateInfo = (DisposeTrackerObject <T> .WatsonThreadStateInfo)stateInfo;
            string text = DisposeTrackerObject <T> .StackTraceToString(watsonThreadStateInfo.StackTrace);

            if (text != null)
            {
                ObjectNotDisposedException <T> exception = new ObjectNotDisposedException <T>(text, watsonThreadStateInfo.StackTraceWasReset);
                try
                {
                    if (watsonThreadStateInfo.ExtraDataList != null)
                    {
                        foreach (WatsonExtraDataReportAction action in watsonThreadStateInfo.ExtraDataList)
                        {
                            ExWatson.RegisterReportAction(action, WatsonActionScope.Thread);
                        }
                    }
                    ExWatson.HandleException(new UnhandledExceptionEventArgs(exception, DisposeTrackerOptions.TerminateOnReport), ReportOptions.DoNotCollectDumps | ReportOptions.DeepStackTraceHash | ReportOptions.DoNotLogProcessAndThreadIds | ReportOptions.DoNotFreezeThreads);
                }
                finally
                {
                    if (watsonThreadStateInfo.ExtraDataList != null)
                    {
                        foreach (WatsonExtraDataReportAction action2 in watsonThreadStateInfo.ExtraDataList)
                        {
                            ExWatson.UnregisterReportAction(action2, WatsonActionScope.Thread);
                        }
                    }
                }
            }
            Thread.CurrentThread.IsBackground = true;
        }
Esempio n. 2
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         base.StackTrace = null;
         return;
     }
     if (DisposeTracker.OnLeakDetected != null && !base.WasProperlyDisposed)
     {
         string arg;
         if (base.StackTrace != null)
         {
             arg = DisposeTrackerObject <T> .StackTraceToString(base.StackTrace);
         }
         else
         {
             arg = "No stack collected. Under HKLM\\SOFTWARE\\Microsoft\\ExchangeServer\\v15\\DisposeTrackerOptions set CollectStackTracesForLeakDetection (DWORD) to 1 and run this whole module again.";
         }
         DisposeTracker.OnLeakDetected(typeof(T).ToString(), arg);
         return;
     }
     try
     {
         if (DisposeTracker.Suppressed || this.IsShuttingDown())
         {
             return;
         }
     }
     catch
     {
         return;
     }
     if (base.StackTrace != null)
     {
         if (Debugger.IsAttached && DisposeTrackerOptions.DebugBreakOnLeak)
         {
             Debugger.Break();
             return;
         }
         if (DisposeTracker.CheckAndUpdateIfCanWatsonThisSecond())
         {
             Task.Factory.StartNew(DisposeTrackerObject <T> .watsonDelegate, new DisposeTrackerObject <T> .WatsonThreadStateInfo(base.StackTrace, base.StackTraceWasReset, base.ExtraDataList));
             return;
         }
     }
     else
     {
         if (DisposeTrackerOptions.Enabled)
         {
             DisposeTrackerObject <T> .isTypeRisky         = true;
             DisposeTrackerObject <T> .numCollectedCounter = 0;
             return;
         }
         DisposeTrackerObject <T> .isTypeRisky = false;
     }
 }