CLR via C # Reading Notes 1-1 when to use a thread or thread pool

Source: Internet
Author: User

Generally, use the thread pool whenever possible.

Except for the following four situations:

  1. The thread needs to be manually controlled to run on a non-default priority (not recommended)
  2. It must be displayed as a foreground thread
  3. It takes a long time to run a task
  4. To manually control the lifecycle of a thread (such as abort)

-------------------------------

In fact, I think there are two more important aspects.

The thread pool is shared globally, that is,ProgramInserting some tasks into the thread pool will inevitably affect others

In extreme cases, you occupy all the objects in the thread pool, and other programs cannot run normally (including some threads of. Net itself)

The key is

Do not occupy the thread pool for a long time or a large amount, unless it can be determined that the current program is the most important program on this server

On a high-pressure server, or your program may consume a large amount of resources, you 'd better implement a controllable thread pool (such as some open-source implementations above codeproject) by yourself ), in this way, you can better control and schedule the use of system resources.

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.