11
public bool HasItemsFromPropertySet(InfoItemPropertySet propertySet, CompositeInfoItem itemRemoved)
    {
        var itemAndSubItems = new InfoItemCollection();
        if (itemRemoved != null)
        {
            itemAndSubItems.Add(itemRemoved);
            //foreach (InfoItem item in itemRemoved.AllDescendants)
            itemAndSubItems.AddRange(itemRemoved.AllDescendants);
        }
        return AllItems.AsParallel().Any(item => item.PropertySet == propertySet && !itemAndSubItems.Contains(item));
    }


Above in my code I use AsParallel().Any() How can i get thread ID of thread generated by that AsParellel.Any()...

moribvndvs
  • 42,191
  • 11
  • 135
  • 149
Recawo
  • 183
  • 1
  • 1
  • 8

1 Answers1

18

Thread.CurrentThread.ManagedThreadId gets the managed thread ID of the currently executing thread.

If you want to get the native thread ID instead (not something you normally want to do) you can call the method AppDomain.GetCurrentThreadId() (obsoleted "because it does not provide a stable Id when managed threads are running on fibers" but as far as I know managed threads are only running on fibers inside SQL Server).

Martin Liversage
  • 104,481
  • 22
  • 209
  • 256
  • 1
    To find thread Id of currently executing thread in above case I have to write Thread.CurrentThread.ManagedThreadId inside AsParallel().Any( item => {//here I guess//}); but That line does not work because that line only contains predicate. – Recawo Apr 19 '12 at 11:01
  • 1
    @Recawo: But what is it that you want to do? Anyway, you can easily create a predicate that queries the current thread ID either by wrapping it into a function or writing it inline like this `item => { ... C# statements ... ; return result; }`. – Martin Liversage Apr 19 '12 at 11:57