private Task<AccountPhoneMark[]> DeleteTask(AccountPhoneMark[] items) { var startTask = Task.Factory.StartNew(() => { IsBusy = true; }, GetCancellationToken(), TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); var clientTask = startTask.ContinueWith((t) => { var client = new RoyaltyServiceWorker.AccountService.AccountServiceClient(); try { return client.RemoveAccountPhoneMarkRange(items.Select(i => i.Id).ToList()); } finally { try { client.Close(); } catch { } } }, GetCancellationToken(), TaskContinuationOptions.AttachedToParent, TaskScheduler.Default); var taskRes = clientTask.ContinueWith((res) => { try { if (res.Result.Error != null) throw new Exception(res.Result.Error); return items .Where(i => !res.Result.Values.Contains(i.Id)) .ToArray(); } catch (Exception ex) { Error = ex.ToString(); return items; } finally { IsBusy = false; } }, GetCancellationToken(), TaskContinuationOptions.AttachedToParent, TaskScheduler.FromCurrentSynchronizationContext()); return taskRes; }