private void HandelProgramChanges() { // First lock the list lock (m_programModifications) { // Loop through all of the changes. foreach (KeyValuePair <GlowPrograms, bool> change in m_programModifications) { if (change.Value) { // We are adding a program= make sure it isn't already active. lock (m_activePrograms) { if (m_activePrograms.ContainsKey(change.Key)) { // The program is already active, continue. break; } } // Now activate it IProgram addProgram = m_programCache[change.Key]; addProgram.Activate(); // And add it to the list. lock (m_activePrograms) { m_activePrograms.Add(change.Key, addProgram); } } else { // We are removing a program, make sure it exists lock (m_activePrograms) { if (!m_activePrograms.ContainsKey(change.Key)) { // The program already doesn't exist break; } } // Deactivate it IProgram addProgram = m_programCache[change.Key]; addProgram.Deactivate(); // Remove it lock (m_activePrograms) { m_activePrograms.Remove(change.Key); } } } // Empty the list m_programModifications.Clear(); } }