I use Tasks to run asynchronous operations in .NET.
In order to make a better use of the Threads debugging window, I would like to identify the currently running task by a thread name. However, the Name property of each thread can only be set once. So the second time the same thread from the pool is used, I’m getting a runtime exception.
Is there any way to get around this?
As Ani notes in his comment: Parallel Tasks Window will give you details of the state of all existing Tasks. This, and the Parallel Stacks, tools window will give better detail for most debugging of tasks.
Thread.Nameallows you to set a thread’s name, but (if I recall correctly) this can only be set once for a single thread rather limiting its usefulness for thread pool threads (tasks run on thread pool threads).