/// <summary> /// Добавление эпизодов /// </summary> public async Task <bool> AddSouthPark() { if (CanAddAddSouthPark is false) { return(false); } AddingFilmCancellationTokenSource = new CancellationTokenSource(); AddingFilmToken = AddingFilmCancellationTokenSource.Token; try { var wvm = new WaitViewModel(); WinMan.ShowWindow(wvm); ((Window)((MainViewModel)Parent).GetView()).IsEnabled = false; await CreateSP(wvm); ((Window)((MainViewModel)Parent).GetView()).IsEnabled = true; wvm.TryClose(); } catch (Exception e) { WinMan.ShowWindow(new DialogViewModel(e.ToString(), DialogType.Error, e)); return(false); } Films = new BindableCollection <Film>(GetDbCollection <Film>()); return(AddingFilmToken.IsCancellationRequested is false); }
public void Execute(ActionExecutionContext context) { TaskScheduler scheduler; if (SynchronizationContext.Current != null) { scheduler = TaskScheduler.FromCurrentSynchronizationContext(); } else { scheduler = TaskScheduler.Current; } var args = new ResultCompletionEventArgs(); Task.ContinueWith(t => { if (t.IsFaulted) { args.Error = t.Exception; } if (t.IsCanceled) { log.Warn($"Отменена задача {viewModel.DisplayName}"); args.WasCancelled = t.IsCanceled; } viewModel.IsCompleted = true; viewModel.TryClose(); if (t.IsFaulted) { Manager.Error(ErrorHelper.TranslateException(t.Exception) ?? viewModel.GenericErrorMessage); } }, scheduler); if (Task.Status == TaskStatus.Created) { Task.Start(TaskScheduler.Default); } Manager.ShowFixedDialog(viewModel); Completed?.Invoke(this, args); }