File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -835,10 +835,16 @@ public string ThreadName
835835 m_data . ThreadName =
836836 SystemInfo . CurrentThreadId . ToString ( System . Globalization . NumberFormatInfo . InvariantInfo ) ;
837837#else
838- m_data . ThreadName = System . Threading . Thread . CurrentThread . Name ;
839- if ( m_data . ThreadName == null || m_data . ThreadName . Length == 0 )
838+ // '.NET ThreadPool Worker' appears as a default thread pool name in .NET 6+.
839+ // Prefer the numeric thread ID instead.
840+ string threadName = System . Threading . Thread . CurrentThread . Name ;
841+ if ( ! string . IsNullOrEmpty ( threadName ) && threadName != ".NET ThreadPool Worker" )
840842 {
841- // The thread name is not available. Therefore we
843+ m_data . ThreadName = threadName ;
844+ }
845+ else
846+ {
847+ // The thread name is not available or unsuitable. Therefore we
842848 // go the the AppDomain to get the ID of the
843849 // current thread. (Why don't Threads know their own ID?)
844850 try
@@ -847,7 +853,7 @@ public string ThreadName
847853 SystemInfo . CurrentThreadId . ToString ( System . Globalization . NumberFormatInfo
848854 . InvariantInfo ) ;
849855 }
850- catch ( System . Security . SecurityException )
856+ catch ( SecurityException )
851857 {
852858 // This security exception will occur if the caller does not have
853859 // some undefined set of SecurityPermission flags.
You can’t perform that action at this time.
0 commit comments