views:

108

answers:

2

I've always been in the habit of naming my threads like this because I read sometime to do so, but it occurred to me that I've never used any debugging tool that showed a thread's name.

When would naming a thread be useful? When would I actually see the name of a thread? Should I name threads for some profiling tools? What tools?

+4  A: 

At the very least, it makes debugging a little quicker when you can quickly identify which thread's state you need to investigate (or switch to or suspend). See also a couple of the answers in this SO question.

Visual Studio has had a threads window at least since VS2003. That MSDN page also features a couple uses of the threads window.

Mark Rushakoff
When in debugging do you see a thread's name?
JamesBrownIsDead
You see a thread's name when you have broken into the debugger and you are viewing the Threads window.
Marty Dill
A: 

Like you, I seldom have use for thread names when debugging. I know the Threads window is there, and I've used it every now and then. And when I have used it, I'm glad that I've named my threads.

That said, I use the name of a thread (System.Threading.Thread.CurrentThread.Name) when logging messages to the Event Viewer, log files, the console, etc. Especially in the case of errors, it provides me that extra insight into what exactly was going on. I use the stack trace to pinpoint the location of the error in the code, and the thread name to give the stack trace some context.

Matt Davis