Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to lock several objects?

Tags:

c#

locking

I want to lock on two objects at the same time. Why can't I write like such code?

lock (obj1, obj2) 

Should I always write like that?

lock (obj1) {     lock (obj2)     {     } } 

Probably this could be made simpler? Likely it would be better to introduce special private object, and use it for a lock...

like image 419
Oleg Vazhnev Avatar asked May 12 '11 09:05

Oleg Vazhnev


People also ask

How do I lock multiple objects in Miro?

Select an object and choose Lock on the context menu or just select the object and use the Ctrl + L (for Windows) or Cmd + L (for Mac) shortcut.

How do I lock an item in place?

Lock an object in placeSelect the Inspector from the toolbar. In the Inspector, select the Lock tab. Select an object (or objects) on the canvas that you would like to lock. Choose Lock.


1 Answers

Well, this question is way too old but, here is a compact one I figured out, both codes will end up to the same compiled statements (this and the one in the question description):

    lock (obj1) lock (obj2)     {         // your code     } 
like image 156
HericDenis Avatar answered Oct 08 '22 10:10

HericDenis