I'm using Monitor.TryEnter(object,int millisecondsTimeout) overload to wait for a lock for no more than X amount of time. Now I'm getting a strange behaviour.
>From what I understand from the specification using this overload I would get the same behaviour as using the lock keyword (C#) but on wait no more than millisecondsTimeout. What I'm getting is the lock is ONLY obtained after millisecondsTimeout elapses EVEN when the lock has been released. Going to try to make graphic representation of a timeline x Seconds 120 seconds (after) -------+--------+-------+--------+-------+--------+-------+--------+ Thread A TryEnter(obj,120000) LOCK_RELEASED Thread B TryEnter(obj,120000); Thread B unblocks Thread A gets hold of the lock first and Thread B blocks. Thread B should unblock on x Seconds and only unblocks after 120 seconds. If I replace TryEnter with lock(obj) thread B unblocks right after thread A has Released the lock. Any thoughts? TIA -- Regard your good name as the richest jewel you can possibly be possessed of - for credit is like fire; when once you have kindled it you may easily preserve it, but if you once extinguish it, you will find it an arduous task to rekindle it again. The way to gain a good reputation is to endeavor to be what you desire to appear." [Socrates] **************************************************************************** Esta mensagem (incluindo eventuais ficheiros anexos) pode conter informacao confidencial ou privilegiada. Se nao for o destinatario pretendido, por favor contacte imediatamente o remetente por e-mail, e apague a mensagem do seu sistema informatico. A transmissao de mensagens por e-mail nao e absolutamente segura ou livre de erro: a mensagem pode ser interceptada, alterada, perdida, destruida, chegar ao seu destinatario num momento posterior ao pretendido ou alterada, ou ainda com virus. O Banco Espirito Santo declina qualquer responsabilidade por erros ou omissoes na presente mensagem que resultem das circunstancias descritas. Qualquer opiniao expressa na presente mensagem e imputavel a pessoa que a enviou, a nao ser que o contrario resulte expressamente do seu texto e que a pessoa em causa tenha poderes para vincular o Banco Espirito Santo. This message and any files transmitted with it may contain confidential information or privileged material. If you are not the intended recipient, please notify the sender immediately by e-mail and delete this message from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. Banco Espirito Santo therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorized to state them to be the views of Banco Espirito Santo. ****************************************************************************