In C # multithreaded programming, about whether to use the thread that you created (threads) or thread pool (ThreadPool) threads, has been very confused, know the Jeffrey Richter the relevant introduction to understand, recorded as follows:
When any of the conditions are met, you can explicitly create your own thread:
1. Threads need to run at a non-trivial thread priority level. All thread pool threads are running at normal priority, although it is not recommended to have the thread pool threads more prioritized. In addition, changes to the priority level are unsustainable between different thread pool operations.
2. A thread is required to behave as a foreground thread to prevent the application from terminating the end of the task. Thread pool threads are always background threads, and if the CLR terminates the process, they may not be able to accomplish the task.
3. The task of calculating the limit needs to run for a long time. Thread pool The logic used to determine whether an additional thread needs to be created is more complex. You can avoid this problem by creating a dedicated thread directly for long-running tasks.
4. To start the thread and possibly call the thread's Abort method to terminate it prematurely.
C # explicitly creates threads or uses thread pool threads--new thread () or ThreadPool.QueueUserWorkItem ()