Threading with the Thread Pool and BackgroundWorker

Threading with the Thread Pool and BackgroundWorker

threadsToday I want to talk about threads since every programmer works with them and absolutely loves them. Typically, when we create a thread, your code can look like this:

static void Main(string[] args)

static void TraditionalThreadCreation()
// Create threads
Thread thread1 = new Thread(Task);
Thread thread2 = new Thread(Task);

// this guy will do even numbers
// this guy will do odd numbers
//wait for first thread to finish

static void Task(object p)
for (int i = int.Parse(p.ToString()); i <=10; i += 2)

There is nothing wrong with creating threads like the code above. But there is one thing you have to keep in mind. Thread creation and startup has overhead. A typical thread can take up 1MB of your precious memory. Shocked?? Well you are not alone. Continue reading