Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8814345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:05:56+00:00 2026-06-14T04:05:56+00:00

The Task Parallel Library and TPL Dataflow allow one to specify the maximum degree

  • 0

The Task Parallel Library and TPL Dataflow allow one to specify the maximum degree of parallelism. That value is a cap, not a guarantee. Indeed the TPL will determine the actual degree of parallelism based on a number of factors including system resources without exceeding any programmer-specified maximum.

Is there some mechanism to determine the choices that TPL has made for the degree of parallelism at a point in time?

I’m asking specifically because I ported some fairly complex code to use TPL Dataflow, and the overall throughput is much less than the original code. I would like to look at what choices TPL has made on my behalf to understand why it is much slower.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:05:57+00:00Added an answer on June 14, 2026 at 4:05 am

    I ran into a very similar situation to yours. I ended up using my logging data to tell me roughly how many threads were being used per minute. This gave me a rough number but not exact.

    I don’t believe TPL can give you telemetry on its use of threads. If you wanted to implement something more exact, I would recommend implementing logic in each Task/Thread to mark some shared list of the time it started and the time it finished. Here is an example of how I would approach it to start off.

    public class DoSomeTPLWork
    {
        public static void Start()
        {
            List<int> numberList = Enumerable.Range(1, 1000).ToList();
    
            Parallel.ForEach(numberList, number =>
                {
                    ThreadTracking.ThreadStarted();
    
                    int square = number * number;
                    Console.WriteLine("Square of {0} is {1}", number, square);
    
                    ThreadTracking.ThreadFinished();
                }
            );
    
            var threadInfo = ThreadTracking.GetThreadInfo();
        }
    }
    
    public class ThreadTracking
    {
        private static ConcurrentBag<ThreadInfo> _threadInfo = new ConcurrentBag<ThreadInfo>();
    
        public static void ThreadStarted()
        {
            var threadInfo = new ThreadInfo(Thread.CurrentThread.ManagedThreadId);
            threadInfo.Start();
            _threadInfo.Add(threadInfo);
        }
    
        public static void ThreadFinished()
        {
            var threadInfo = _threadInfo.Where(ti => ti.ThreadId == Thread.CurrentThread.ManagedThreadId && !ti.Complete).SingleOrDefault();
            if(threadInfo != null)
            {
                threadInfo.Stop();
            }
        }
    
        public static List<ThreadInfo> GetThreadInfo()
        {
            return _threadInfo.ToList();
        }
    }
    
    public class ThreadInfo
    {
        public bool Complete { get; set; }
        public int ThreadId { get; set; }
        public DateTime? TimeStarted { get; set; }
        public DateTime? TimeFinished { get; set; }
    
        public ThreadInfo(int threadId)
        {
            ThreadId = threadId;
        }
    
        public void Start()
        {
            TimeStarted = DateTime.Now;
            Complete = false;
        }
    
        public void Stop()
        {
            TimeFinished = DateTime.Now;
            Complete = true;
        }
    }
    

    Using the data, you can see how many threads are being used for any given second by adding on some more methods to query the data or just popping it in Excel to play with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently researching Task Parallel Library and I read somewhere that TPL actually
I understand that the new TPL (Task Parallel Library) has implemented the Parallel.ForEach such
I am studying task parallel library for .NET (TPL) , I am trying to
I'm using the TPL ( Task Parallel Library ) in .NET 4.0. I want
I heard that the Task Parallel Library can be used in a .Net 3.5
I have a long-running Task that I've implemented using the Task Parallel Library. When
I'm new to the TPL (Task-Parallel Library) and am wondering if the following is
I have been following the development of the .NET Task Parallel Library (TPL) with
I know that Task Parallel Library is still in Beta and there are likely
I'm using Task Parallel Library (TPL ) for calculating Fibonacci number. Program is given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.