+ [TestFixture]
+ public class ThreadStateTest {
+ void Start ()
+ {
+ }
+
+ [Test] // bug #81720
+ public void IsBackGround ()
+ {
+ Thread t1 = new Thread (new ThreadStart (Start));
+ Assert.AreEqual (ThreadState.Unstarted, t1.ThreadState, "#A1");
+ Assert.IsFalse (t1.IsBackground, "#A2");
+ t1.Start ();
+ t1.Join ();
+ Assert.AreEqual (ThreadState.Stopped, t1.ThreadState, "#A3");
+
+ try {
+ bool isBackGround = t1.IsBackground;
+ Assert.Fail ("#A4: " + isBackGround.ToString ());
+ } catch (ThreadStateException ex) {
+ Assert.AreEqual (typeof (ThreadStateException), ex.GetType (), "#A5");
+ Assert.IsNull (ex.InnerException, "#A6");
+ Assert.IsNotNull (ex.Message, "#A7");
+ }
+
+ Thread t2 = new Thread (new ThreadStart (Start));
+ Assert.AreEqual (ThreadState.Unstarted, t2.ThreadState, "#B1");
+ t2.IsBackground = true;
+ Assert.AreEqual (ThreadState.Unstarted | ThreadState.Background, t2.ThreadState, "#B2");
+ Assert.IsTrue (t2.IsBackground, "#B3");
+ t2.Start ();
+ t2.Join ();
+ Assert.AreEqual (ThreadState.Stopped, t2.ThreadState, "#B4");
+
+ try {
+ bool isBackGround = t2.IsBackground;
+ Assert.Fail ("#B5: " + isBackGround.ToString ());
+ } catch (ThreadStateException ex) {
+ Assert.AreEqual (typeof (ThreadStateException), ex.GetType (), "#B6");
+ Assert.IsNull (ex.InnerException, "#B7");
+ Assert.IsNotNull (ex.Message, "#B8");
+ }
+ }
+ }
+