I am looking through some C# code and I am seeing something I cannot figure out near the class definition. Here is a sample of what I am seeing.
[MethodImpl(MethodImplOptions.Synchronized)]
public void AddTag(RTag tag)
{
this.tags.Add(tag)
}
What the heck is the first line doing or stating? I have not been able to track it down in any of my reference books.
Thanks!
The first line is an attribute, i.e. meta data attached to the method.
The MethodImplAttribute specifies the details of how a method is implemented. In particular, MethodImplOptions.Synchronized
Specifies that the method can be executed by only one thread at a time. Static methods lock on the type, whereas instance methods lock on the instance. Only one thread can execute in any of the instance functions, and only one thread can execute in any of a class's static functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With