Re: synchronous call

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




> Again, you didn't show anything that you were trying to synchronize, so ... synchronized code is substituted for simplicity by A.func() this is code that only one thread needs to be in. if I make it static and use this attribute (thanks for the attribute), my problem's fixed.

example:

using System.Runtime.CompilerServices;

class A
{
  [MethodImplAttribute(MethodImplOptions.Synchronized)]
  public static void func() {}
}

thread1:
A a1 = new A();
a1.func();

thread2:
A a2 = new A();
a2.func();


Ivan


Nicholas Paldino [.NET/C# MVP] wrote:
Ivan,

Check out the MethodImpl attribute, and pass in the MethodImplOptions.Synchronized value to the attribute.

However, this will make any call on the object (you need to apply it to every method) hold whenever any other method is called on any other thread.



.