walking the call stack from within a thread. Getting the parent call stack

  • Thread starter Thread starter Jason Coyne
  • Start date Start date
J

Jason Coyne

I am trying to use the StackTrace class to get my current stack trace
for some logging. Everything is working fine, except when I am using
threading (specifically WaitCallBack and ThreadPool.QueueUserWorkItem)

When I try to walk the stack from a location that has been called via
QueueUserWorkItem, the stack stops at the point where the thread was
launched. Is there a way to walk back further into the parent thread's
stack (at the time that my own thread was created, not the current
state)

Thanks, Jason.
 
Every thread maintains it's own call stack. Hence the start of the
QueueUserWorkItem is the first entry into the thread stack. As far as I
know, the parent thread will have a current stack trace which you can get,
but not the stack trace at the time of the thread launch.

One solution is for every thread to preserve the parent stack trace as the
first item it executes and use this information for logging purpose.

Hope this helps
Shuvro
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top