C# FAQ: How can I port synchronized functions from Visual Jplusplus?

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:FAQs
edit

How can I port synchronized functions from Visual J++ to C#?

Here is a Visual J++ source code example of a synchronized method:

public synchronized void Run() 
{
   // method body
}

The following is a port of the Visual J++ synchronized method to C# source code:

class Test
{
   public void Run()
   {
      lock (this)
      {
         // method body 
      }
   }
 
   public static void Main() {}
 
}

Be aware that there are many subtleties and pitfalls associated with the lock keyword.



Personal tools