0

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();
                    }
                }
Brian
  • 6,910
  • 8
  • 44
  • 82

1 Answers1

1

Actually is not the same think the Application.Lock(); with the lock(app)

The Application.Lock(); is lock all threads on pools, the lock(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();

public void Lock()
{
    this._lock.AcquireWrite();
}

internal virtual void AcquireWrite()
{
    lock (this)
    {
        while (this._lock != 0)
        {
            try
            {
                Monitor.Wait(this);
                continue;
            }
            catch (ThreadInterruptedException)
            {
                continue;
            }
        }
        this._lock = -1;
    }
}
Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150