예제 #1
0
            internal ResourceLockerToken(ResourceLocker <T> resourceLocker)
            {
                if (resourceLocker == null)
                {
                    throw new ArgumentNullException("resourceLocker");
                }

                _resourceLocker = resourceLocker;

                int tires = 120;

                bool success = false;

                while (!success && tires-- > 0)
                {
                    IDisposable coreLock = null;

                    try
                    {
                        if (_resourceLocker._requireCoreReaderLock)
                        {
                            coreLock = GlobalInitializerFacade.CoreNotLockedScope;
                        }

                        _resourceLocker.TryEnterLock(500, ref success);
                    }
                    finally
                    {
                        if (coreLock != null)
                        {
                            coreLock.Dispose();
                        }
                    }

                    if (!success)
                    {
                        Thread.Sleep(1);
                    }
                }

                if (!success)
                {
                    throw new TimeoutException("Failed to obtain a required resource lock. Aborting to avoid system deadlocks.");
                }
            }