I am using .AsParallel().ForAll() to enumerate a collection in parallel in the context of an ASP.NET request. The enumeration method relies on System.Threading.Thread.CurrentPr
This is the implementation behind CurrentPrincipal
public static IPrincipal CurrentPrincipal
{
get
{
lock (CurrentThread)
{
IPrincipal threadPrincipal = CallContext.Principal;
if (threadPrincipal == null)
{
threadPrincipal = GetDomain().GetThreadPrincipal();
CallContext.Principal = threadPrincipal;
}
return threadPrincipal;
}
}
set { CallContext.Principal = value; }
}
All newly created threads will have null and it will be taken from application domain. So it should be ok. Nevertheless you need be careful with culture. It will not be derived from starting thread. See: Parallel Programing, PLINQ and Globalization