[英]ReactiveUI: How to cancel an Observable from a ReactiveCommand?
I have the following: 我有以下内容:
Compress = this.WhenAnyValue(x => x.ImagesCount, x => x > 0).ToCommand();
var process = Compress.RegisterAsync(ConvertImages);
var subscription = process.Subscribe(x => Images.Remove(x));
CancelConversion = this.WhenAnyValue(x => x.ImagesCount, x => x.IsBusy, (count, busy) => count > 0 && busy).ToCommand();
CancelConversion.RegisterAsyncAction();
Where ConvertImages(object o)
is a private method of the ViewModel that, in turn, calls and returns the result of ConvertImages(IEnumerable<ImageDto> images)
in a service class that resizes and compresses the images and returns an IObservable<ImageDto>
. 其中ConvertImages(object o)
是ViewModel的私有方法,该方法又在服务类中调用并返回ConvertImages(IEnumerable<ImageDto> images)
,该服务类将调整图像的大小并压缩并返回IObservable<ImageDto>
。
Paul Betts suggests here to implement cancellation via the implementation of my IObservable
eg using Observable.create
, so can anyone provide an example of how to implement such Observable? Paul Betts建议在此处通过使用IObservable
的实现来实现取消,例如使用Observable.create
,那么有人可以举例说明如何实现这种Observable吗?
Also what is the RxUI™ way to signal this cancellation? 还有RxUI™发出取消信号的方式是什么? Should I subscription.Dispose()
in CancelConversion.RegisterAsyncAction()
? 我应该subscription.Dispose()
在CancelConversion.RegisterAsyncAction()
Should I add .TakeUntil(CancelConversion.Execution_Signaled)
to var process
, how can I determine "CancelConversion.Execution_Signaled"? 我应该将.TakeUntil(CancelConversion.Execution_Signaled)
添加到var process
,如何确定“ CancelConversion.Execution_Signaled”?
This is fairly easy: 这很简单:
CancelConversion = this.WhenAnyValue(x => x.ImagesCount, x => x.IsBusy, (count, busy) => count > 0 && busy).ToCommand();
this.WhenAnyValue(x => x.ImagesCount, x => x > 0).ToCommand();
var process = Compress.RegisterAsync(x => ConvertImages().TakeUntil(CancelConversion));
var subscription = process.Subscribe(x => Images.Remove(x));
Handling the actual cancellation (ie stopping whatever work that ConvertImages is really doing) depends on your implementation of ConvertImages. 处理实际取消(即停止ConvertImages实际所做的任何工作)取决于您对ConvertImages的实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.