private void DeleteClosingEventHandler(object sender, DialogClosingEventArgs args) { bool result = false; if (Equals(args.Parameter, false)) { return; } if (Equals(args.Parameter, "Cancel")) { return; } if (_isOkMessageOpen) { _isOkMessageOpen = false; return; } if (Equals(args.Parameter, "Ok")) { args.Cancel(); args.Session.UpdateContent(new PleaseWaitView()); Task.Run(() => { try { //_context.Entry(SelectedPartyList).State = EntityState.Deleted; _context.PartyLists.Remove(SelectedPartyList); foreach (var entity in CouncilMembersList) { //_context.Entry(entity).State = EntityState.Deleted; _context.CouncilMembers.Remove(entity); } _context.SaveChanges(); result = true; } catch (Exception e) { Console.WriteLine(e.Message); result = false; } Thread.Sleep(1000); return(result); }).ContinueWith( (t, _) => { if (!t.Result) { _isOkMessageOpen = true; args.Session.UpdateContent(new OkMessageDialog() { DataContext = "Failed to Delete" }); } else { foreach (var member in CouncilMembersList.ToList()) { CouncilMembersList.Remove(member); } PartyLists.Remove(SelectedPartyList); RaisePropertyChanged(() => PartyLists); //PartyLists = new List<PartyList>(); args.Session.Close(false); } }, null, TaskScheduler.FromCurrentSynchronizationContext()); } }