Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get thread Id in C#

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()...

like image 520
Recawo Avatar asked Apr 19 '12 09:04

Recawo


Video Answer


1 Answers

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).

like image 117
Martin Liversage Avatar answered Oct 12 '22 02:10

Martin Liversage