Introduction This article is about muilti – threading concept in .NET explained using C# as programming language. Multi threading is an important aspect that needs a special attention while building very huge system, especially when there is a trade off between efficiency (how fast the system works?) and performance (how correctly the system works?). With [...]

We’ve seen how the lock syntax, and how mutexes, can be used for synchronization. However, using these in their simplest forms is not always sufficient. Consider a situation, where you have a limited number of resources, but greater than 1, with multiple threads trying to access these resources. Assume you have 5 “amounts” of this [...]

You might come across a situation where you need to write a multithreading Windows Application, where multiple threads make updates to the UI. The main purpose of this chapter is to inform you regarding one important issue you need to take care of. Create a new Windows Application Project. To the main form, add a [...]

Lets start with a simple application. Have a look at the code below: class BankAccount { public int Money; } class Program { static void Main (string[] args) { BankAccount account = new BankAccount(); account.Money = 100; Thread oneDollarThread = new Thread(new ParameterizedThreadStart(AddOneDollar)); Thread twoDollarThread = new Thread(new ParameterizedThreadStart(AddTwoDollars)); oneDollarThread.Start(account); twoDollarThread.Start(account); Thread.Sleep(4000); Console.WriteLine(“Amount of money [...]

The Thread Class: Once you’ve decided what work needs to be done in a separate thread by your application, you need to create an object of the Thread class. The Thread class is used for creating threads, controlling them, and for terminating them. I’ll show you how to use this class for creating a thread [...]

Your computer most probably has only one processor. One processor can carry out only one task at a time. But most probably, you run multiple applications simultaneously. How do they all work together even though you have only one processor? The answer is – multitasking. The operating system on your machine allocates the use of [...]