C# Lock Statement

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.


  • Output

    My name is Steven Clark


    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#.

    One thought on “C# Lock Statement”

    1. Great tutorial, sir.
      Could you please modify the example code to show us the “failed attempt” to access the locked resource by another thread for better understanding? Something like this perhaps:

      Thank you for your time.

    Leave a Reply

    Your email address will not be published. Required fields are marked *