O'Reilly logo

Visual Studio 2012 and .NET 4.5 Expert Development Cookbook by Abhishek Sur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Introduction to Threading and Asynchronous Threading patterns

Threads have been around for a long time. It is said that to support concurrency, operating systems need to create threads and run two blocks of code in parallel. So when we create threads, we create one more execution context and when we start a thread the operating system automatically schedules a thread which will run in parallel while executing the program. Threads ensure that while executing one operation, the other operation remains either idle or shares the CPU, executing its own code in parallel.

Let us consider the following code:

static void Main(string[] args) { Thread thNew = new Thread(WriteThreadName); thNew.Name = "Worker Thread"; Thread.CurrentThread.Name = "Main Thread"; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required