Can a stream be named in the Visual Studio debugger?

I work in C # 4.0 (winforms), debugging an application with 10+ threads. During debugging, there is a drop-down menu to choose which thread I should debug (available only during breakpoints).

They are displayed as "Thread Win32", "Workflow", "RPC Reverse Flow", etc.

I would like to name them from my code. I execute all my threads using background workers.

Edit: my decision. This may not work in 100% of cases, but it does exactly what he needs. If in some cases the labels are wrong, this is normal in the context with which I work.

In each backgroundworker * _dowork event, I put the following line of code in:

ReportData.TrySetCurrentThreadName(String.Format("{0}.{1}", MethodBase.GetCurrentMethod().DeclaringType, MethodBase.GetCurrentMethod().Name)); 

What...

  public static void TrySetCurrentThreadName(String threadName) { if (System.Threading.Thread.CurrentThread.Name == null) { System.Threading.Thread.CurrentThread.Name = threadName; } } 
+7
source share
2 answers

Well, you can use the Thread.Name property, but you can write only once - so when you create a thread, give it the appropriate name.

+9
source
 Thread.CurrentThread.Name = "Give your name here"; 
+1
source

All Articles