码迷,mamicode.com
首页 > 其他好文 > 详细

提供者模式:提供者的实例化加锁

时间:2017-06-07 23:14:12      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:create   cti   config   catch   double   syn   实例   read   logs   

private static void LoadProviders()
{
    // providers are loaded just once
    if (null == _providers)
    {
        // Synchronize the process of loading the providers
        lock (SyncLock)
        {
            // Double confirm that the _provider is still null.
            if (null == _provider)
            {
                try
                {
                    // Reads the webconfig file corresponding node.
                    DataProviderSection section = (DataProviderSection)
                                                  WebConfigurationManager.GetSection("system.web/dataProviderService");

                    _providers = new DataProviderCollection();

                    // Creates provider instance, and invokes ProviderBase‘s Initialize function.
                    ProvidersHelper.InstantiateProviders(section.Providers, Providers, typeof(DataProvider));

                    // Gets the default in the collection.
                    _provider = Providers[section.DefaultProvider];
                }
                catch
                {
                    throw new ProviderException("Can‘t create instance");
                }
            }
        }
    }
}

 

提供者模式:提供者的实例化加锁

标签:create   cti   config   catch   double   syn   实例   read   logs   

原文地址:http://www.cnblogs.com/DaphneOdera/p/6959302.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!