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
One subtle thing to notice when passing Principal through .AsParallel() boundary: Where your sequence gets materialized?
This isn't a problem with .ForAll(), but consider another scenario:
var result = items.AsParallel().Select(MyTransform);
Then you're passing result elsewhere so that it crosses thread boundary (which is likely, say, if you're returning it out of WCF action method).
In this case by the time MyTransform gets applied, Thread.CurrentPrincipal value might contain something unexpected.
So, the workaround here is to materialize query on the spot (by calling .ToArray(), .ToList(), etc.)