I understand the basic purpose of Multithreading. I also know that we can use Asynchronous Programming Model, BackgroundWorkerComponent, or simply calling a task on another thread, for achieving concurrency. But I don’t understand the basic differences among these 3 ways of achieving concurrency. Can anyone please make it clear to me.
Thanks in advance.
I understand the basic purpose of Multithreading. I also know that we can use
Share
Using the Asynchronous Programming Model or a BackgroundWorker Component, you are using two different models (APIs) to run code on a Thread Pool thread.
The BackgroundWorker’s model is fairly simple, but well-suited for certain types of task. BackgroundWorker follows the (obsolete) Event-based Asynchronous Pattern (EAP). Generally I would prefer APM unless the task is a great fit for BackgroundWorker.
Using the thread pool can be advantageous because there is a certain overhead to create a thread (such as allocating the stack space for the thread, etc.).
When you create a thread on your own, you are not using a Thread Pool thread (unless you invoke an appropriate API to access one). Thus, you pay the cost of creating the thread. If your thread is fairly long-running, this can be a reasonable thing to do because the cost is amortized over the lifetime of the thread, and you are not consuming one of the limited Thread Pool threads.
I would point out that your question did not reference
http://msdn.microsoft.com/en-us/library/hh873175.aspx
which is recommended for all new development.