/// <summary> /// 初始化 /// </summary> public static void Init() { string path = GetSettingsFilePath(); if (!File.Exists(path)) { throw new FileNotFoundException("上传控件的配置文件不存在!"); } // 注意啦:访问文件是可能会出现异常。不要学我,我写的是示例代码。 var settings = Deserialize(path); int flag = System.Threading.Interlocked.CompareExchange(ref s_UploadSettingsCacheDependencyFlag, 1, 0); // 确保只调用一次就可以了。 if (flag == 0) { // 让Cache帮我们盯住这个配置文件。 CacheDependency dep = new CacheDependency(path); HttpRuntime.Cache.Insert(_cacheKey, "yxl", dep, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, UploadSettingsUpdateCallback); } _instance = settings; }
static UploadHelper() { UploadSettings.Init(); }