Example #1
0
        /// <summary>
        /// Searches the Configuration Providers for an entry with the specified name
        /// </summary>
        /// <param name="name">Name of the entry to find</param>
        /// <returns>Value of the found entry or null if none found</returns>
        public static object GetSetting(string name)
        {
            object returnValue = null;

            _lock.AcquireReaderLock(LockTimeout);

            if (_lock.IsReaderLockHeld)
            {
                try
                {
                    if (_settings != null)
                    {
                        returnValue = _settings.GetSetting(name);
                    }
                    else
                    {
                        LockCookie lockCookie = _lock.UpgradeToWriterLock(LockTimeout);
                        if (_lock.IsWriterLockHeld)
                        {
                            _settings = new InternalSettings();
                            _lock.DowngradeFromWriterLock(ref lockCookie);
                            returnValue = _settings.GetSetting(name);
                        }
                        else
                        {
                            throw new ApplicationException("Could not obtain lock to reopen settings system");
                        }
                    }
                }
                finally
                {
                    _lock.ReleaseReaderLock();
                }
            }
            return returnValue;
        }