Identifying the location of a given thread

After identifying a specific thread of interest, is it possible to programmatically get its location at runtime?

In other words, I want to see which method this thread is executing:

var executingThread = System.Threading.Thread.CurrentThread;

I know I can find this information in the Threads window when debugging in VisualStudio, but I am stumped about if this can be obtained in code.

My goal is to periodically log the location of the stream that I am monitoring in a lengthy process.

+3


source to share


1 answer


By definition, you have to introduce a race condition - by the time another thread noticed that the monitored thread was executing MethodX

, it could have jumped to MethodY

- as it will be constantly running. Or you could watch MethodX

when you look, but spend most of your time in MethodY

. What you want to do can be done with debuggers and profilers - this will be your best bet and most reliable.



+1


source







All Articles