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
835
835
m_data . ThreadName =
836
836
SystemInfo . CurrentThreadId . ToString ( System . Globalization . NumberFormatInfo . InvariantInfo ) ;
837
837
#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" )
840
842
{
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
842
848
// go the the AppDomain to get the ID of the
843
849
// current thread. (Why don't Threads know their own ID?)
844
850
try
@@ -847,7 +853,7 @@ public string ThreadName
847
853
SystemInfo . CurrentThreadId . ToString ( System . Globalization . NumberFormatInfo
848
854
. InvariantInfo ) ;
849
855
}
850
- catch ( System . Security . SecurityException )
856
+ catch ( SecurityException )
851
857
{
852
858
// This security exception will occur if the caller does not have
853
859
// some undefined set of SecurityPermission flags.
You can’t perform that action at this time.
0 commit comments