Skip to content

Gendarme.Rules.Concurrency.DoNotLockOnWeakIdentityObjectsRule(git)

Sebastien Pouliot edited this page Mar 2, 2011 · 1 revision

DoNotLockOnWeakIdentityObjectsRule

Assembly: Gendarme.Rules.Concurrency
Version: git

Description

This rule ensures there are no locks on objects with weak identity. An object with weak identity is one that can be directly accessed across different application domains. Because these objects can be accessed by different application domains it is very difficult to ensure that the locking is done correctly so problems such as deadlocks are much more likely. The following types have a weak identities:

Examples

Bad example:

public void WeakIdLocked ()
{
    lock ("CustomString") {
        // ...
    }
}

Good example:

public void WeakIdNotLocked ()
{
    Phone phone = new Phone ();
    lock (phone) {
        // ...
    }
}

Source code

You can browse the latest source code of this rule on github.com

Clone this wiki locally