public void StorageFiresEventTest()
        {
            using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
            {
                StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
                IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
                Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));

                using (IConfigurationChangeWatcher watcher = storage.CreateConfigurationChangeWatcher())
                {
                    watcher.ConfigurationChanged += new ConfigurationChangedEventHandler(OnConfigurationChanged);

                    watcher.StartWatching();
                    Thread.Sleep(100);
                    ((IStorageProviderWriter)storage).Write(GetData());

                    for (int wait = 0; wait < 10 && eventFiredCount < 2; ++wait)
                    {
                        Thread.Sleep(500);
                    }

                    watcher.Dispose();
                }

                Assert.AreEqual(1, eventFiredCount);
            }
        }
Beispiel #2
0
        public void Remove(string sectionName)
        {
            if (null == sectionName)
            {
                return;
            }

            lock (lockMe)
            {
                Cache.Remove(sectionName);
                IConfigurationChangeWatcher watcher = (IConfigurationChangeWatcher)ConfigurationWatcherCache[sectionName];
                if (watcher != null)
                {
                    ConfigurationWatcherCache.Remove(sectionName);
                    watcher.Dispose();
                }
            }
        }