Synchronized attribute - when should we use it?

B

beginwithl

hi

I haven’t yet covered the attributes and object contexts, so I may be
missing something quite obvious …


1) Say we have class A marked with [synchronized] attribute and
instance B of that class.

I assume using synchronized attribute on B in essence produces same/
similar effects as if all methods of B would have lock inside of them
and as if all these locks would use same private object as a token?!


2) In what situations would we choose synchronized attribute over
Monitor.Enter()? One situation I can think of is if we wanted all
instance methods of a class to be synchronized, but there must be
other reasons also?!

thank you
 
B

beginwithl

hi


I apologize for not replying sooner, I won’t go into any details,
since I’m sure you’re not in the least interested, but due to hectic
week I’ve hardly managed to get any PC time

1) Say we have class A marked with [synchronized] attribute and
instance B of that class.

What attribute is that?

Sorry about that. Seems I always manage to get something wrong – it’s
actually called [synchronization] attribute and it is used to lock
down all method instance member code:

[Synchronization]
public class A
{ … }



cheers
 
B

beginwithl

hi

See:

http://msdn.microsoft.com/en-us/lib...m/en-us/library/system.enterpriseservices.syn...

Neither of these attributes are general-purpose synchronization attributes.

I don't know anything about contexts, except that for class to be
created within one, it needs to be derived from
System.ContextBoundObject class. Only to such a class can we apply
synchronization attribute ( System.Runtime.Remoting.Contexts
namespace ).

Assuming we're dealing with such a class, is the assumption I made
under my first question correct?

cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top