I have a project and a class library.
I need the class library to update storage items. In my project I need to access these storage items. Can I use lock on the same instance from different projects and will this work?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
So long as you’re locking on genuinely the same object, that should work absolutely fine. If you were using different AppDomains things would get more complicated, but if it’s just (say) both Project A and Project B locking on an object which originally came from Project C, that shouldn’t be a problem.
At least, it’ll work technically. Personally I usually prefer to keep locks as private as possible – for example, rather than locking on
thisor a reference obtained from elsewhere, I’ll often create an object whose sole purpose is locking:That way I know that the only code which can acquire that lock is code in
Foo. It makes the locks easier to reason about.