/// <summary> /// Asynchronous save of ObservableCollection<AccountList>. /// </summary> public async void SaveAccountList() { if (AccountsList == null) { return; } //remove all empty rows. for (int i = AccountsList.Count - 1; i >= 0; i--) { if (AccountsList[i].IsEmpty) { AccountsList.RemoveAt(i); } } KeyFile key; if (File.Exists(settings.keyLocation)) { //load key from appdata. key = await CryptoTools.LoadStoredKeyFile(settings.keyLocation); } else { //create new keyfile if none created yet in appdata. key = await CryptoTools.CreateStoredKeyFile(settings.keyLocation); } //encrypt accountlist into byte array. byte[] listAsBytes = CryptoTools.EncryptData(key.key, key.IV, AccountsList); //save encrypted accountlist await FileManager.SaveFileAsync(settings.saveFileLocation, listAsBytes, false); }