/// <summary> /// Disposes of the device detection providers. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Application_End(object sender, EventArgs e) { if (_pattern != null) { _pattern.Dispose(); _pattern = null; } if (_trie != null) { _trie.Dispose(); _trie = null; } }
/// <summary> /// Performs dataset reload tests. A number of threads run in the /// background constantly performing device detection while the main /// thread does the data file reloads. /// /// The main thread will carry on doing the dataset reloads while at /// least one thread has not finished. /// </summary> public void Run() { // Threads that run device detection in the background. int numberOfThreads = 4; // Contains references to background threads. Thread[] threads; Console.WriteLine("Starting the Reload Data File Example."); provider = new TrieWrapper(deviceDataFile, propertiesToUse); threads = new Thread[numberOfThreads]; // Start detection threads. for (int i = 0; i < numberOfThreads; i++) { threads[i] = new Thread(new ThreadStart(threadPayload)); threads[i].Start(); } // Reload data file until at least one thread is still not done. while (threadsFinished < numberOfThreads) { provider.ReloadFromMemory(); Console.WriteLine("Provider reloaded."); Thread.Sleep(1000); } // Wait for all detection threads to complete. for (int i = 0; i < numberOfThreads; i++) { threads[i].Join(); } // Release resources held by the provider. provider.Dispose(); // Perform the test. if (!cb.IsEmpty) { long first, current; cb.TryTake(out first); while (!cb.IsEmpty) { cb.TryTake(out current); Assert.IsTrue(first == current, "Hash values are not equal."); } } }