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; } }
greggorob64
source share