Exemplo n.º 1
0
        public SchemaCollection GetSchemas()
        {
            if (_schemas == null)
            {
                var schemas = System.Threading.Interlocked.CompareExchange(ref _schemas, new SchemaCollection(), null);

                if (schemas == null)
                {
                    //加载Schema到结果集中
                    this.LoadSchemas(_schemas, _category);

                    //更新最后加载的时间
                    _lastLoadTime = DateTime.Now;

                    //返回加载完成的模式集
                    return(_schemas);
                }
            }

            if ((DateTime.Now - _lastLoadTime).TotalMinutes > 1)
            {
                //在后续加载中必须先清空原有内容,否则很可能会产生键冲突
                _schemas.Clear();

                //加载Schema到结果集中
                this.LoadSchemas(_schemas, _category);

                //更新最后加载的时间
                _lastLoadTime = DateTime.Now;
            }

            return(_schemas);
        }