Fixed loop limit bug in Task.TryRemove for the ObservableConcurrentCollection.
[pithos-ms-client] / trunk / Pithos.Client.WPF / Preferences / PreferencesViewModel.cs
index 1b8a400..fbe78fe 100644 (file)
@@ -42,6 +42,7 @@
 
 
 using System.Collections.Concurrent;
+using System.Collections.Generic;
 using System.ComponentModel.Composition;
 using System.Diagnostics;
 using System.IO;
@@ -280,6 +281,12 @@ namespace Pithos.Client.WPF.Preferences
             Settings.Save();
             //SetStartupMode();            
 
+            foreach (var account in _accountsToRemove)
+            {
+                Settings.Accounts.Remove(account);
+                Shell.RemoveMonitor(account.AccountName);
+            }
+
             foreach (var account in Settings.Accounts)
             {                                
                 Shell.MonitorAccount(account);
@@ -374,20 +381,18 @@ namespace Pithos.Client.WPF.Preferences
             NotifyOfPropertyChange(()=>Settings);                       
        }
 
+
+        readonly List<AccountSettings> _accountsToRemove = new List<AccountSettings>();
         public void RemoveAccount()
         {
             var accountName = CurrentAccount.AccountName;
-            Settings.Accounts.Remove(CurrentAccount.Account);
 
             Accounts.TryRemove(CurrentAccount);
-            
-            
+            _accountsToRemove.Add(CurrentAccount.Account);
+
             CurrentAccount = null;
-            //Accounts = Settings.Accounts;
-            //Settings.Save();            
-            Shell.RemoveMonitor(accountName);
             NotifyOfPropertyChange(() => Accounts);
-            NotifyOfPropertyChange(() => Settings);                       
+
             
             //NotifyOfPropertyChange("Settings.Accounts");
         }