I'm creating an ASP.net website which handles thousands of requests and it all stems from one main object that they all share to read it. I'm trying to wrap my head around these different types of locks.
Some common questions i have for each.
- What is the scope of each lock Application, Session,Object
- When is it right to use one over the other?
- Can multiple users run the code in the lock at one time?
- Performance Hit?
1.
public class MyClass
{
lock
{
// DO COOL CODE STUFF.
}
}
2.
public class MyClass
{
Application.Lock
// DO COOL CODE STUFF.
Application.Unlock
}
3.
public static object lockObject = new object();
public class MyClass
{
lock(lockObject)
{
// DO COOL CODE STUFF.
}
}
4.
private static readonly ReaderWriterLockSlim slimLock = new ReaderWriterLockSlim();
public class MyClass
{
slimLock.EnterWriteLock();
// DO COOL CODE STUFF HERE.
slimLock.ExitWriteLock();
}