C # multithreading 10-thread pool,

Source: Internet
Author: User

C # multithreading 10-thread pool,

TheadPool: if you do not want to frequently create threads during multi-threaded programming, you can use the thread pool to complete multi-threaded programming. You only need to deliver the tasks to be processed to the ThreadPool. If there are Idle threads in the ThreadPool, The ThreadPool will distribute the tasks you have delivered to an idle thread for execution; if there are no Idle threads available in the ThreadPool, The ThreadPool will automatically create a thread to process the tasks you deliver.

The threads in ThreadPool can also be synchronized with the content mentioned in this series of articles. Therefore, this question only demonstrates the basic usage of the Thread Pool. I hope you can learn how to use the ThreadPool through this question, then, we can further explore it in the actual development process.

private static void MultiThreadWithTheadPool()        {            ThreadPool.QueueUserWorkItem(args =>            {                for (var i = 0; i < 5; i++)                {                    Console.WriteLine(i);                    Thread.Sleep(200);                }            });            ThreadPool.QueueUserWorkItem(args =>            {                for (var i = 10; i < 15; i++)                {                    Console.WriteLine(i);                    Thread.Sleep(200);                }            });        }

Note: by the end of this blog, the basic knowledge of C # multithreading has come to an end. You should be able to quickly start multi-threaded development after you have mastered the above knowledge. There are many problems in the practical use of multithreading, such as modifying the control content in WinFom development.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.