Interview Tips Interview Tips, Interview Questions and Answers

9Jun/100

How does multi-threading work in .NET?

There are two main ways of multi-threading which .NET encourages:

To start your own threads with ThreadStart delegates, you should create a new thread "manually" for long-running tasks.

Using the ThreadPool class either directly (using ThreadPool.QueueUserWorkItem) or indirectly using asynchronous methods (such as Stream.BeginRead, or calling BeginInvoke on any delegate).

Use the thread pool only for brief jobs.

Benefits of using the Thread Pool.

Benefits of using the Thread Pool.

The benefits of using a Thread Pool are:

Thread creation and destruction overhead is negated,
Better performance and better system stability.
It is better to use a thread pool in cases where the number of threads is very large.