RequiresThreadAttribute
Marks a test that must run on a separate thread.
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using System;
using System.Runtime.CompilerServices;
using System.Threading;
namespace NUnit.Framework
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class RequiresThreadAttribute : PropertyAttribute, IApplyToTest
{
public RequiresThreadAttribute()
: base(true)
{
}
public RequiresThreadAttribute(ApartmentState apartment)
: base(true)
{
Guard.ArgumentValid(apartment != ApartmentState.Unknown, "must be STA or MTA", "apartment");
base.Properties.Add("ApartmentState", apartment);
}
[System.Runtime.CompilerServices.NullableContext(1)]
void IApplyToTest.ApplyToTest(Test test)
{
test.RequiresThread = true;
base.ApplyToTest(test);
}
}
}