Cosa fa MethodImplOptions.Synchronized?Cosa fa MethodImplOptions.Synchronized?
è il codice qui sotto
[MethodImpl(MethodImplOptions.Synchronized)]
public void Method()
{
MethodImpl();
}
equivalente a
public void Method()
{
lock(this)
{
MethodImpl();
}
}
Questo è vero per i metodi e le proprietà di istanza, ma per quelli statici si blocca sul tipo, che [va contro le migliori pratiche ] (http://michaelprimeaux.com/blog/2008/01/09/methodimploptions-dot-synchronized/) e in realtà ha un noto [bug su sistemi x64] (https://connect.microsoft.com/VisualStudio/feedback/details/423280/methodimpl-methodimploptions-synchronized-intermittently-throws-synchronizationlockexception-when-used-on-static-method-on-x64) th a causa dell'eccezione delle eccezioni di sincronizzazione dell'oggetto. – Shaun