What does MethodImplOptions.Synchronized do?
.NetMultithreading.Net Problem Overview
What does MethodImplOptions.Synchronized
do?
Is the code below
[MethodImpl(MethodImplOptions.Synchronized)]
public void Method()
{
MethodImpl();
}
equivalent to
public void Method()
{
lock(this)
{
MethodImpl();
}
}
.Net Solutions
Solution 1 - .Net
This was answered by Mr. Jon Skeet on another site.
Quote from Post
> It's the equivalent to putting lock(this) round the whole method call.
The post has more example code.
Solution 2 - .Net
For static methods it's the same as:
public class MyClass
{
public static void Method()
{
lock(typeof(MyClass))
{
MethodImpl();
}
}
}
Solution 3 - .Net
Yes it is. See MethodImplOptions Enumeration