public static void EndEvent() { if (!_CaptureAllowed) { return; } Debug.WriteLine(string.Format("EndEvent : ThreadId {0}", Thread.CurrentThread.ManagedThreadId)); long tickCount = _Timer.ElapsedTicks; try { //get the local thread callstack data Stack <CallStackItem> callStack = GetThreadCallStack(); //un-pile the last start event CallStackItem info = callStack.Pop(); info.TotalTick = tickCount - info.TotalTick; Debug.WriteLine(string.Format("EndEvent depile: method {0}, ThreadId {1}", info.MethodHandle, Thread.CurrentThread.ManagedThreadId)); if (callStack.Count != 0) { //the one before is the one that called me CallStackItem infoCaller = callStack.Peek(); info.CalledByHandle = infoCaller.MethodHandle; } //write the log CallStackLogger.Instance.Write(info); //if no more call on the stack, flush the log writer if (callStack.Count == 0) { CallStackLogger.Instance.Flush(); _ThreadSlotCount--; Debug.WriteLine(string.Format("EndEvent : nb slot {0}, ThreadId {1}", _ThreadSlotCount, Thread.CurrentThread.ManagedThreadId)); Thread.SetData(_ThreadLocalSlot, null); } //no more threads with a start event and a callstack if (_ThreadSlotCount == 0) { CallStackLogger.Instance.Terminate(); if (_Host != null) { _Host.StopService(); } } } catch (Exception exception) { RuntimeLogger.Instance.Log(LogType.Error, "ReflectionStudio.Spy.Performance.EndEvent", exception); } }