小编Val*_*nik的帖子

ReactiveCommand的前后行动

我想在命令执行之前设置忙标志和状态栏文本,并在完成后重置标志和文本.我的工作代码在这里:

Cmd = ReactiveCommand.Create();
Cmd.Subscribe(async _ => 
{
    IsBusy = true;
    StatusBarText = "Doing job...";
    try
    {
        var organization = await DoAsyncJob();
        //do smth w results
    }
    finally
    {
        IsBusy = false;
        StatusBarText = "Ready";
});
Run Code Online (Sandbox Code Playgroud)

是否有可能以"正确的方式"做到这一点?像这样:

Cmd = ReactiveCommand.CreateAsyncTask(_ => DoAsyncJob());
//how to do pre-action?
//is exists more beautiful way to to post-action?
Cmd.Subscribe(res =>
{
    try
    {
        //do smth w results
    }
    finally
    {
        IsBusy = false;
        StatusBarText = "Ready";
    }
});
Run Code Online (Sandbox Code Playgroud)

或这个:

Cmd = ReactiveCommand.CreateAsyncTask(_ => DoAsyncJob()); …
Run Code Online (Sandbox Code Playgroud)

c# system.reactive reactiveui

2
推荐指数
1
解决办法
702
查看次数

标签 统计

c# ×1

reactiveui ×1

system.reactive ×1