public void LetsOthersUseNappingThreadsCorrectly( ) { int i = 0; object _lock = new object(); ThreadManager tman = new ThreadManager(1, 1); // Using this to test interaction very specifically. tman.WaitForThreadSpawns(); ActionTask task = new ActionTask(( _ ) => { _.IsNapping = true; }, false); task.Extend(( _ ) => i = 100); tman.EnqueueTask(task); for ( int j = 0; j < 10; j++ ) tman.EnqueueTask(new ActionTask(( _ ) => { lock ( _lock ) i++; }, false)); tman.UnsafeUpdate(); for ( int j = 0; j < 100; j++ ) if ( task.IsNapping ) break; else System.Threading.Thread.Sleep(1); for ( int j = 0; j < 10; j++ ) { tman.UnsafeUpdate(); System.Threading.Thread.Sleep(1); lock ( _lock ) Assert.AreEqual(j + 1, i, "Ran some number other than 1 of the Tasks at once on update #" + j); } task.IsNapping = false; tman.UnsafeUpdate(); System.Threading.Thread.Sleep(1); Assert.AreEqual(100, i, "Did not run awakened Task."); tman.Dispose(); }