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;
//TimeSpan MaxValue = TimeSpan.FromMilliseconds ((long) Int32.MaxValue);
TimeSpan TooLarge = TimeSpan.FromMilliseconds ((long) Int32.MaxValue + 1);
- static bool is_win32;
- static bool is_mono;
-
- static ThreadTest ()
- {
- switch (Environment.OSVersion.Platform) {
- case PlatformID.Win32NT:
- case PlatformID.Win32S:
- case PlatformID.Win32Windows:
- case PlatformID.WinCE:
- is_win32 = true;
- break;
- }
-
- // check a class in mscorlib to determine if we're running on Mono
- if (Type.GetType ("Mono.Runtime", false) != null)
- is_mono = true;
- }
-
//Some Classes to test as threads
private class C1Test
{
[Category ("NotDotNet")] // it hangs.
public void TestStart()
{
- if (is_win32 && is_mono)
- Assert.Fail ("This test fails on Win32. The test should be fixed.");
{
C1Test test1 = new C1Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
[Test]
public void TestApartmentState ()
{
- if (is_win32 && is_mono)
- Assert.Fail ("This test fails on mono on win32. Our runtime should be fixed.");
-
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
Assert.AreEqual (ApartmentState.Unknown, TestThread.ApartmentState, "#1");
[Category ("NotWorking")] // setting the priority of a Thread before it is started isn't implemented in Mono yet
public void TestPriority1()
{
- if (is_win32 && is_mono)
- Assert.Fail ("This test fails on mono on Win32. Our runtime should be fixed.");
-
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
try {
[Test]
public void TestIsBackground1 ()
{
- if (is_win32 && is_mono)
- Assert.Fail ("This test fails on mono on Win32. Our runtime should be fixed.");
-
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
try {
[Test]
public void TestName()
{
- if (is_win32 && is_mono)
- Assert.Fail ("This test fails on mono on Win32. Our runtime should be fixed.");
-
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
try {
[Test]
public void TestThreadState ()
{
- if (is_win32 && is_mono)
- Assert.Fail ("This test fails on mono on Win32. Our runtime should be fixed.");
-
//TODO: Test The rest of the possible transitions
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
[Category("NotDotNet")] // On MS, ThreadStateException is thrown on Abort: "Thread is suspended; attempting to abort"
public void TestSuspendAbort ()
{
- if (is_win32 && is_mono)
- Assert.Fail ("This test fails on Win32. The test should be fixed.");
-
Thread t = new Thread (new ThreadStart (DoCount));
t.IsBackground = true;
t.Start ();
}
[Test]
- [Category ("NotDotNet")] // it crashes nunit.
public void Test_InterruptCurrentThread ()
{
ManualResetEvent mre = new ManualResetEvent (false);
#if MONO_FEATURE_MULTIPLE_APPDOMAINS
[Test]
+ [Category ("NotDotNet")]
public void CurrentThread_Domains ()
{
AppDomain ad = AppDomain.CreateDomain ("foo");
}
#endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
+ [Test]
+ public void SetNameInThreadPoolThread ()
+ {
+ Task t = Task.Run (delegate () {
+ Thread.CurrentThread.Name = "ThreadName1";
+ Assert.AreEqual (Thread.CurrentThread.Name, "ThreadName1", "#1");
+
+ try {
+ Thread.CurrentThread.Name = "ThreadName2";
+ Assert.Fail ("#2");
+ } catch (InvalidOperationException) {
+ }
+ });
+
+ t.Wait ();
+ }
+
void CheckIsRunning (string s, Thread t)
{
int c = counter;