Thread.Start() versus ThreadPool.QueueUserWorkItem()

前端 未结 7 2087
长发绾君心
长发绾君心 2020-12-12 16:20

The Microsoft .NET Base Class Library provides several ways to create a thread and start it. Basically the invocation is very similar to every other one providing the same k

7条回答
  •  囚心锁ツ
    2020-12-12 17:03

    You should use ThreadPool.QueueUserWorkItem except in cases of:

    • You require a foreground thread.

    • You require a thread to have a particular priority.

    • You have tasks that cause the thread to block for long periods of time. The thread pool has a maximum number of threads, so a large number of blocked thread pool threads might prevent tasks from starting.

    • You need to place threads into a single-threaded apartment. All ThreadPool threads are in the multithreaded apartment.

    • You need to have a stable identity associated with the thread, or to dedicate a thread to a task.

    Reference link.

提交回复
热议问题