Connecting Tech Pros Worldwide Forums | Help | Site Map

detecting object lock?

Hyun-jik Bae
Guest
 
Posts: n/a
#1: Mar 10 '07
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?=
Guest
 
Posts: n/a
#2: Mar 10 '07

re: detecting object lock?


Hyun-jik Bae wrote:
Quote:
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.

--
Göran Andersson
_____
http://www.guffa.com
Closed Thread