File tree 1 file changed +28
-0
lines changed
src/libraries/System.Threading.Thread/tests
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -1298,5 +1298,33 @@ public static void GetCurrentProcessorId()
1298
1298
{
1299
1299
Assert . True ( Thread . GetCurrentProcessorId ( ) >= 0 ) ;
1300
1300
}
1301
+
1302
+ [ DllImport ( "kernel32.dll" , CharSet = CharSet . Unicode , SetLastError = true ) ]
1303
+ private static extern int GetThreadDescription ( IntPtr hThread , out IntPtr threadDescription ) ;
1304
+
1305
+ [ DllImport ( "kernel32.dll" , SetLastError = true ) ]
1306
+ private static extern IntPtr GetCurrentThread ( ) ;
1307
+
1308
+ [ ConditionalFact ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsThreadingSupported ) ) ]
1309
+ public static void NameNativeThreadBeforeStart ( )
1310
+ {
1311
+ string threadName = "Test thread name" ;
1312
+
1313
+ Thread t = new Thread ( ( ) =>
1314
+ {
1315
+ IntPtr threadHandle = GetCurrentThread ( ) ;
1316
+ GetThreadDescription ( threadHandle , out IntPtr threadDescriptionPtr ) ;
1317
+
1318
+ string nativeThreadName = Marshal . PtrToStringUni ( threadDescriptionPtr ) ;
1319
+ Marshal . FreeHGlobal ( threadDescriptionPtr ) ; // Free the unmanaged memory
1320
+ Assert . Equal ( threadName , nativeThreadName ) ;
1321
+ } ) {
1322
+ Name = threadName
1323
+ } ;
1324
+
1325
+ t . IsBackground = true ;
1326
+ t . Start ( ) ;
1327
+ Assert . True ( t . Join ( UnexpectedTimeoutMilliseconds ) ) ;
1328
+ }
1301
1329
}
1302
1330
}
You can’t perform that action at this time.
0 commit comments