Is CompilerServices.MethodImpl(MethodImplOptions.Synchronized) recommended?

  • Thread starter Thread starter buu
  • Start date Start date
B

buu

wich would be best practice for multithreaded apps?

I have a sub in a class that is called from a multiple threads, and I found
MethodImpl to lock a sub when a thread enters.

is it reccommended and best practice way?
does it makes lock on sub or on whole class?
 
buu said:
wich would be best practice for multithreaded apps?

I have a sub in a class that is called from a multiple threads, and I found
MethodImpl to lock a sub when a thread enters.

is it reccommended and best practice way?
does it makes lock on sub or on whole class?

For a static method, it's the equivalent of doing lock(TypeName). For
an instance method it's the equivalent of doing lock(this).

Personally I'd avoid it, and lock on a more specific reference.
See http://pobox.com/~skeet/csharp/threads/lockchoice.shtml
 
Back
Top