mirror of
https://github.com/farcasclaudiu/SmartThreadPool.git
synced 2026-06-22 09:01:19 +03:00
Added ApartmentState to threads + tests
This commit is contained in:
@@ -109,6 +109,7 @@
|
||||
<Compile Include="AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="TestThreadApartmentState.cs" />
|
||||
<Compile Include="TestParallelMethods.cs" />
|
||||
<Compile Include="TestFalseFillStateWithParams.cs" />
|
||||
<Compile Include="TestFillStateWithParams.cs" />
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user