detecting object lock?

H

Hyun-jik Bae

Is there any way knowing if an object is locked, for example, "lock(object)
{...}" ?

Please reply. Thanks in advance.

Hyun-jik Bae
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Hyun-jik Bae said:
Is there any way knowing if an object is locked, for example, "lock(object)
{...}" ?

Please reply. Thanks in advance.

Hyun-jik Bae

You can use Monitor.TryEnter(theObject) to try to use the object in a
lock. If it returns false, the object is already used in a lock. If it
returns true, you have successfully used it in a lock.

Note: Using an object in a lock doesn't protect the object in any way,
it only stops any other code to use the same object in a lock.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top