ReactiveUI异常处理ReactiveCommand.CreateAsyncTask的恢复

时间:2015-05-29 22:35:26

标签: reactiveui

查看ReactiveUI ReactiveCommands的许多示例,代码类似于

Delete = ReactiveCommand.CreateAsyncObservable(x => DeleteImpl());
Delete.IsExecuting.ToProperty(this, x => x.IsDeleting, out _isDeleting);
Delete.ThrownExceptions.Subscribe(ex => this.Log().ErrorException("Something went wrong", ex));

我正在尝试使用CreateAsyncTask代替CreateAsyncObservable

Delete = ReactiveCommand.CreateAsyncTask(x => DeleteImpl());
Delete.IsExecuting.ToProperty(this, x => x.IsDeleting, out _isDeleting);
Delete.ThrownExceptions.Subscribe(ex => this.Log().ErrorException("Something went wrong", ex));

Delete command绑定到WPF按钮。

使用CreateAsyncObservable,从错误恢复后启用该按钮。

使用CreateAsyncTask,该按钮被禁用。

除了使用CreateAsyncObservable(逻辑已经写成异步方法)之后,如何在错误后重新启用按钮?

1 个答案:

答案 0 :(得分:0)

我正在使用的被叫方法签名导致了这个问题。

    private Task<Unit> DeleteImpl()
    {
        throw new NotImplementedException();
    }

缺少async关键字

将方法更改为

    private async Task<Unit> DeleteImpl()
    {
        throw new NotImplementedException();
    }