Multithreading in C#

In C# we can starts in a single thread created automatically by the CLR and operating system (the “main” thread), and is made multithreaded by creating additional threads. First have a look at a simple example:

The main thread creates a new thread t on which it runs a method that repeatedly prints the character “HI”. Simultaneously, the main thread repeatedly prints the character “hi”. Output is:


Local variables are kept separate as the CLR assigns each thread its own memory stack. For e.g.:

Output is:



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s