K
KK
Dear All
My requirement is to write class that is thread safe.( All public methods &
static methods must be thread safe ).
I found two options to implement this
1.using MethodImplOptions.Synchronized attribute
2.Using Lock statement
Class using method 1:
public class X
{
[MethodImpl(MethodImplOptions.Synchronized)]
public void X1()
{
}
[MethodImpl(MethodImplOptions.Synchronized)]
public void X2()
{
}
}
Class using method 2:
public class Y
{
public void Y1()
{
lock(this)
{
}
}
public void Y2()
{
lock(this)
{
}
}
}
Can somebody explain me what are the advantages & disadvantages with
these two approaches?
Thanks in advance.
Best Regards
Krishna
My requirement is to write class that is thread safe.( All public methods &
static methods must be thread safe ).
I found two options to implement this
1.using MethodImplOptions.Synchronized attribute
2.Using Lock statement
Class using method 1:
public class X
{
[MethodImpl(MethodImplOptions.Synchronized)]
public void X1()
{
}
[MethodImpl(MethodImplOptions.Synchronized)]
public void X2()
{
}
}
Class using method 2:
public class Y
{
public void Y1()
{
lock(this)
{
}
}
public void Y2()
{
lock(this)
{
}
}
}
Can somebody explain me what are the advantages & disadvantages with
these two approaches?
Thanks in advance.
Best Regards
Krishna