In this chapter you will learn:
- What is Lock Statement in C#?
- What is the benefit of using lock statement in C#?
- How to use it in C# programming?
The lock statement handle lock segment as a critical section and lock the object during the execution of program from other thread. Once the execution is completed it releases the lock and frees objects.
public void printname()
Console.WriteLine("My name is Steven Clark");
static void Main(string args)
Program p = new Program();
// creating lock segment. all the resources that is used in lock segment, can't be used by another thread until it releases.
In this chapter, you learned what Lock statement is in C# and how to use it in C# programming. In next chapter you will learn about Using Statement in C#.