I have moved from java to C# and confused about wait() and sleep().
In java, sleep would not remove the lock to an object and after sleep completes threads gows back to work and in case of wait, it does removes lock from the object and allows other threads to access that object for a while.
Is this true in C# as well or there are any differences?
Yes, this is true in C# as well. For the most part,
Thread.sleep,Object.wait,Object.notify,Object.notifyAllin Java correspond closely toThread.Sleep,Monitor.Wait,Monitor.Pulse,Monitor.PulseAllin .NET.I’d expect a few differences in details like fairness, but the basics work the same way.
However, you should rarely be using these low-level abstractions in modern code, either in Java or C# – in Java, use higher level abstractions in
java.util.concurrent, and in .NET try to use theTaskabstraction if you can (and if you’re in .NET 4). In particular, usingTaskwill prepare you for the feast of asynchrony in C# 5 (and WinRT).