Curious,
No, it will not. Since the calls are occuring on the same thread, you
will not be blocked.
However, it is a bit inefficient, and it would be better if you did
something like this:
public void Postpone(int key)
{
// Lock on the queue.
lock (myQueue)
{
InternalPostpone(key);
}
}
private void InternalPostpone(int key)
{
object = myQueue.Remove(key);
try
{
myQueue.Add(object, key+1);
}
catch(Exception)
{
InternalPostpone(key+1);
}
}
This way, you don't have excessive locks being allocated on the same
thread.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Curious" <th****@mail.global.net.mt> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi,
I have a datastructure that sorts elements by a key. Now in some
circumstances a key may occur twice and so I would like to change the
old key value by adding 1.
To do this I am doing it recursively within a lock statement. My
problem is that since the myQueue is already locked, if the method is
called again recursively, should it block on the lock statement till
the lock is released?
public void Postpone(key)
{
lock(myQueue)
{
object = myQueue.Remove(key);
try
{
myQueue.Add(object, key+1);
}
catch(Exception)
{
Postpone(key+1);
}
}
}
Can somone help me out
Thanks in Advance