[threads] Allow resetting the name of a threadpool thread (#4350)
[mono.git] / mcs / class / corlib / Test / System.Threading / ThreadTest.cs
index 4c6694f1e17f137b4112f86e51c0081a24041b53..ae5bdbfd586d3391d656861047590897068957ca 100644 (file)
@@ -13,6 +13,7 @@ using System;
 using System.Globalization;
 using System.Security.Principal;
 using System.Threading;
+using System.Threading.Tasks;
 using System.Reflection;
 using System.Collections.Generic;
 using SD = System.Diagnostics;
@@ -908,6 +909,25 @@ namespace MonoTests.System.Threading
                }
 #endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
 
+               [Test]
+               public void SetNameInThreadPoolThread ()
+               {
+                       for (int i = 0; i < 10; ++i) {
+                               Task t = Task.Run (delegate () {
+                                       Thread.CurrentThread.Name = "x/" + i;
+                                       Assert.AreEqual (Thread.CurrentThread.Name, "x/" + i, "#1");
+
+                                       try {
+                                               Thread.CurrentThread.Name = "y/" + i;
+                                               Assert.Fail ("#2");
+                                       } catch (InvalidOperationException) {
+                                       }
+                               });
+
+                               t.Wait ();
+                       }
+               }
+
                void CheckIsRunning (string s, Thread t)
                {
                        int c = counter;