|
using System.Threading;
using NUnit.Framework;
using Amib.Threading;
namespace SmartThreadPoolTests
{
/// <summary>
/// Summary description for TestThreadApartment.
/// </summary>
[TestFixture]
[Category("TestThreadApartment")]
public class TestThreadApartmentState
{
[Test]
public void TestSTA()
{
CheckApartmentState(ApartmentState.STA);
}
[Test]
public void TestMTA()
{
CheckApartmentState(ApartmentState.MTA);
}
private static void CheckApartmentState(ApartmentState requestApartmentState)
{
STPStartInfo stpStartInfo = new STPStartInfo();
stpStartInfo.ApartmentState = requestApartmentState;
SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
IWorkItemResult<ApartmentState> wir = stp.QueueWorkItem(() => GetCurrentThreadApartmentState());
ApartmentState resultApartmentState = wir.GetResult();
stp.WaitForIdle();
Assert.AreEqual(requestApartmentState, resultApartmentState);
}
private static ApartmentState GetCurrentThreadApartmentState()
{
return Thread.CurrentThread.GetApartmentState();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
B.Sc. in Computer Science.
Works as Software Developer.