public void StopTrace() { int currentThreadID = /*get thread*/ GetThreadID(); TracedThread existingThread = this.GetThreadBy(currentThreadID); if (existingThread != null) { existingThread.StopTrace(); } }
internal void StartTrace() { var stackTrace = new StackTrace(skipFrames: 2); StackFrame stackFrame = stackTrace.GetFrame(0); MethodBase method = stackFrame.GetMethod(); TracedThread tracedThread = tracedThreads.GetOrAdd(Thread.CurrentThread.ManagedThreadId, new TracedThread()); tracedThread += method; }
public void StartTrace() { //Get method and thread from StackTrace; MethodBase currentMethod = new StackTrace(1).GetFrame(0).GetMethod(); //Console.WriteLine(currentMethod.Name); int currentThreadID = /*get thread*/ GetThreadID(); TracedThread existingThread = this.GetThreadBy(currentThreadID); if (existingThread == null) { TracedThread newThread = new TracedThread(currentThreadID); threads.Add(currentThreadID, newThread); existingThread = newThread; } existingThread.StartTrace(/*with: */ currentMethod); }