mirror of
https://github.com/farcasclaudiu/SmartThreadPool.git
synced 2026-06-22 11:01:28 +03:00
47 lines
1.1 KiB
C#
47 lines
1.1 KiB
C#
using System.Threading;
|
|
using NUnit.Framework;
|
|
using Amib.Threading;
|
|
|
|
namespace SmartThreadPoolTests
|
|
{
|
|
/// <summary>
|
|
/// Summary description for TestThreadPriority.
|
|
/// </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();
|
|
}
|
|
}
|
|
} |