I am using DotNetOpenAuth in conjunction with Mono 2.10. When context.Application.Unlock() is called, an exception is thrown indicating the lock was never acquired in the first place. I’ve modified the code as shown below.
My question is, does the code serve the same purpose, and does mono under Apache even support locking in this way?
Original
context.Application.Lock();
try
{
if ((store = (IRelyingPartyApplicationStore)context.Application[ApplicationStoreKey]) == null)
{
context.Application[ApplicationStoreKey] = store = new StandardRelyingPartyApplicationStore();
}
}
finally
{
context.Application.UnLock();
}
My Modifications
lock (app)
{
try
{
if ((store = (IRelyingPartyApplicationStore)context.Application[ApplicationStoreKey]) == null)
{
context.Application[ApplicationStoreKey] = store = new StandardRelyingPartyApplicationStore();
}
}
finally
{
//context.Application.UnLock();
}
}
Actually is not the same think the
Application.Lock();with thelock(app)The
Application.Lock();is lock all threads on pools, thelock(app)can lock only current pool threads.If you have problems with the Application data, then save them in a static variable and there you can use the
lock(), and its faster and suggested by microsoft.for more details read also this similar answer: https://stackoverflow.com/a/10964038/159270
By the way this is the code of the
Application.Lock();