Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.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-订阅ThrownExceptions不会防止应用程序崩溃_C#_Wpf_Reactiveui - Fatal编程技术网

C# ReactiveCommand-订阅ThrownExceptions不会防止应用程序崩溃

C# ReactiveCommand-订阅ThrownExceptions不会防止应用程序崩溃,c#,wpf,reactiveui,C#,Wpf,Reactiveui,根据文档(),订阅ThrownExceptions可以防止应用程序崩溃。我有以下代码(为了简单起见,我将命令放在代码中): public分部类主页面:ReactiveUserControl { private ReactiveCommand Test=ReactiveCommand.Create(()=>抛出新异常(“这将使应用程序崩溃!”); 公共主页() { 初始化组件(); 当激活时(d=> { Test.ThrownExceptions.Subscribe(ex=> { 日志错误(ex)

根据文档(),订阅ThrownExceptions可以防止应用程序崩溃。我有以下代码(为了简单起见,我将命令放在代码中):

public分部类主页面:ReactiveUserControl
{
private ReactiveCommand Test=ReactiveCommand.Create(()=>抛出新异常(“这将使应用程序崩溃!”);
公共主页()
{
初始化组件();
当激活时(d=>
{
Test.ThrownExceptions.Subscribe(ex=>
{
日志错误(ex);
}).处置(d);
Test.Execute().Subscribe().DisposeWith(d);
});
}
}

应用程序仍然崩溃,我不知道为什么?

ThrownExceptions不能阻止异常停止应用程序。只是报告他们发生了什么。文件对这一点有点含糊不清将使用更清晰的文档进行更新。好的,我明白了,所以我可能应该使用
Execute().Catch(…)
。这些文件很容易引起误解。
public partial class MainPage : ReactiveUserControl<MainPageViewModel>
{
    private ReactiveCommand<Unit, Unit> Test = ReactiveCommand.Create(() => throw new Exception("This will crash the app!"));

    public MainPage()
    {
        InitializeComponent();
        
        this.WhenActivated(d =>
        {
            Test.ThrownExceptions.Subscribe(ex =>
            {
               Log.Error(ex);
            }).DisposeWith(d);

            Test.Execute().Subscribe().DisposeWith(d);
            
        });
    }
}