ThreadUtility
ThreadUtility provides a set of static methods convenient
for working with threads.
using System;
using System.Runtime.CompilerServices;
using System.Security.Principal;
using System.Threading;
namespace NUnit.Framework.Internal
{
[System.Runtime.CompilerServices.NullableContext(2)]
[System.Runtime.CompilerServices.Nullable(0)]
public static class ThreadUtility
{
internal static void BlockingDelay(int milliseconds)
{
Thread.Sleep(milliseconds);
}
public static IPrincipal GetCurrentThreadPrincipal()
{
try {
return Thread.CurrentPrincipal;
} catch (PlatformNotSupportedException) {
return null;
}
}
public static void SetCurrentThreadPrincipal(IPrincipal principal)
{
try {
Thread.CurrentPrincipal = principal;
} catch (PlatformNotSupportedException) when (principal == null) {
}
}
}
}