private void HandleActivation(CompositeDisposable d) { // Create command. StartCommand = ReactiveCommand .CreateFromObservable(() => { Logs.Clear(); return(Locator.Current.GetService <OneOfRequirement>() .TimeConsumingTask(new OneOfRequest()) .TakeUntil(CancelCommand) .SubscribeOn(ThreadPoolScheduler.Instance)); }); // Create cancellation command. CancelCommand = ReactiveCommand .Create(() => { }, StartCommand.IsExecuting) .DisposeWith(d); // Register the process that when the command progress received. StartCommand .SubscribeProgress(progress => { ProgressPercentage = progress.Percentage; Logs.Add(new LogItem() { Time = DateTime.Now, Message = progress.Notification }); if (progress.IsCompleted) { Logs.Add(new LogItem() { Time = DateTime.Now, Message = "Task completed." }); } }); // Register the process that when the command error received. StartCommand .ThrownExceptions .Subscribe(error => { ProgressPercentage = 0; Logs.Add(new LogItem() { Time = DateTime.Now, Message = error.Message }); }); // Register the process that when the command was cancelled. CancelCommand .Subscribe(_ => { ProgressPercentage = 0; Logs.Add(new LogItem() { Time = DateTime.Now, Message = "Your pizza was cancelled." }); }) .DisposeWith(d); }