Skip to content

Commit 41fdb77

Browse files
committed
Possible app crash fixed, when icollection is refreshed
1 parent 27a243a commit 41fdb77

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

Source/NETworkManager/Models/Settings/CredentialManager.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using System.Security.Cryptography;
1111
using System.Text;
1212
using System.Xml.Serialization;
13+
using System.Windows;
14+
using System.Windows.Threading;
1315

1416
namespace NETworkManager.Models.Settings
1517
{
@@ -97,7 +99,7 @@ private static void DeserializeFromByteArray(byte[] xml)
9799
}
98100

99101
public static void Save()
100-
{
102+
{
101103
// Serialize as xml (utf-8)
102104
byte[] credentials = SerializeToByteArray();
103105

@@ -144,12 +146,22 @@ public static void SetMasterPassword(SecureString masterPasword)
144146

145147
public static void AddCredential(CredentialInfo credential)
146148
{
147-
Credentials.Add(credential);
149+
// Possible fix for appcrash --> when icollection view is refreshed...
150+
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
151+
{
152+
lock (Credentials)
153+
Credentials.Add(credential);
154+
}));
148155
}
149156

150157
public static void RemoveCredential(CredentialInfo credential)
151158
{
152-
Credentials.Remove(credential);
159+
// Possible fix for appcrash --> when icollection view is refreshed...
160+
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
161+
{
162+
lock (Credentials)
163+
Credentials.Remove(credential);
164+
}));
153165
}
154166

155167
#region Encryption / Decryption

Source/NETworkManager/Models/Settings/ProfileManager.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.IO;
5+
using System.Windows;
6+
using System.Windows.Threading;
57
using System.Xml;
68
using System.Xml.Serialization;
79
using MahApps.Metro.Controls.Dialogs;
@@ -111,7 +113,12 @@ public static void Reset()
111113

112114
public static void AddProfile(ProfileInfo profile)
113115
{
114-
Profiles.Add(profile);
116+
// Possible fix for appcrash --> when icollection view is refreshed...
117+
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
118+
{
119+
lock (Profiles)
120+
Profiles.Add(profile);
121+
}));
115122
}
116123

117124
public static void AddProfile(ProfileViewModel instance)
@@ -250,7 +257,12 @@ public static void AddProfile(ProfileViewModel instance)
250257

251258
public static void RemoveProfile(ProfileInfo profile)
252259
{
253-
Profiles.Remove(profile);
260+
// Possible fix for appcrash --> when icollection view is refreshed...
261+
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
262+
{
263+
lock (Profiles)
264+
Profiles.Remove(profile);
265+
}));
254266
}
255267

256268
public static void RenameGroup(string oldGroup, string group)
@@ -297,7 +309,7 @@ public static async void ShowAddProfileDialog(IProfileManager viewModel, IDialog
297309
viewModel.OnProfileDialogOpen();
298310
await dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
299311
}
300-
312+
301313
public static async void ShowEditProfileDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator, ProfileInfo selectedProfile)
302314
{
303315
var customDialog = new CustomDialog

0 commit comments

Comments
 (0)