A.func() needs to be application-wide thread safe.
Having the example in mind, if a1 enters func(), a2 should wait.
example:
class A
{
void func() {}
}
thread1:
A a1 = new A();
a1.func();
thread2:
A a2 = new A();
a2.func();
Ivan
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.
Again, you didn't show anything that you were trying to synchronize, so
this is the most generic code you could use.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> A.func() needs to be application-wide thread safe.
> Having the example in mind, if a1 enters func(), a2 should wait.
[quoted text clipped - 14 lines]
>
> Ivan
Ivan - 14 Dec 2005 21:54 GMT
> 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
> Ivan,
>
[quoted text clipped - 3 lines]
> 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.