Listing 5: Only one class function’s lock block can execute at a time

#using <mscorlib.dll>
using namespace System;
using namespace System::Threading;

__gc class Th05
{
public:
   static void M1()
   {
      // ...
      Monitor::Enter(__typeof(Th05));
      try
      {
         // read from a file
      }
      __finally
      {
         Monitor::Exit(__typeof(Th05));
      }
      // ...
   }

   public static void M2()
   {
      // ...
   static void M2()
   {
      // ...
      Monitor::Enter(__typeof(Th05));
      try
      {
         // update a display
      }
      __finally
      {
         Monitor::Exit(__typeof(Th05));
      }
      // ...
   }
};
— End of Listing —