Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 异常后如何保持ReactiveCommand活动?_C#_Observable_Reactiveui - Fatal编程技术网

C# 异常后如何保持ReactiveCommand活动?

C# 异常后如何保持ReactiveCommand活动?,c#,observable,reactiveui,C#,Observable,Reactiveui,我尝试使用以下代码段: LinkCurrentMailToCase = ReactiveCommand.CreateFromObservable(() => MyAPI.AddMailToCase(CurrentMailItem, CurrentCase)); LinkCurrentMailToCase .ThrownExceptions.Select(ex => ex.Message).ToProperty(this, vm => vm.ErrorMessage, out

我尝试使用以下代码段:

LinkCurrentMailToCase = ReactiveCommand.CreateFromObservable(() => MyAPI.AddMailToCase(CurrentMailItem, CurrentCase));

LinkCurrentMailToCase .ThrownExceptions.Select(ex => ex.Message).ToProperty(this, vm => vm.ErrorMessage, out errorMessage);
然后我将一个按钮绑定到LinkCurrentMailToCase。在抛出异常之前,这一切正常,在这种情况下,我的LinkCurrentMailToCase不再被调用


从我在不同帖子中读到的内容来看,这是可观察对象的正常行为,但我不知道如何设置我的ErrorMessage,如果在保持可观察对象活动的同时引发异常。

代码段中的命令在失败后仍然可以再次调用,不必为此使用
Catch
。但是,如果您订阅了命令本身,但它失败了,那么除了通过
ThrownExceptions
进行管道传输之外,它将在
OnError
回调(如果您有)中结束

这完全取决于您如何调用命令,如果您使用
BindCommand
或使用另一个可观察对象的
InvokeCommand
管道命令,则该命令应按所述工作


但是,如果您使用
.Execute().Subscribe()
并且没有注册
OnError
处理程序(例如使用
Catch
),那么来自命令的可观察管道将中断。

在挣扎之后(习惯了reactiveui的这种情况以及它缺少样本/文档),我想我应该使用Catch(observeable.Return(Unit))与上面提到的ThrownException一起使用。实际上,我将LinkCurrentMailToCase命令绑定到一个按钮上,当它到达ThrownException后,它将不再工作,除非我使用Catch。通常情况下,情况不应该是这样的,例如,您可以在GitHub上共享一个更完整的复制/项目吗?