No, not as long as you are locking on the same object. The recursive code effectively already has the lock and so can continue.
This is because lock(object) {...}
is shorthand for using the Monitor class. As Marc points out, Monitor
allows re-entrancy thus this will work.
If you start locking on different objects, that's when you have to be careful to avoid deadlocks. Especially if you're not acquiring the them in the same sequence.
One further note, your example isn't technically recursive. For it to be recursive, Bar()
would have to call itself, typically as part of an iteration.
Here is one good webpage describing thread synchronisation in .NET: http://dotnetdebug.net/2005/07/20/monitor-class-avoiding-deadlocks/