hwhoops,看起来你已经发现了一个bug在RegisterAsyncAction
,它应该返回IObservable<Unit>
在此期间,只需复制粘贴修正版本到您的应用程序,它只是一个扩展方法:
/// <summary>
/// RegisterAsyncAction registers an asynchronous method that runs
/// whenever the Command's Execute method is called and doesn't return a
/// result.
/// </summary>
/// <param name="calculationFunc">The function to be run in the
/// background.</param>
public static IObservable<Unit> RegisterAsyncAction(this IReactiveAsyncCommand This,
Action<object> calculationFunc,
IScheduler scheduler = null)
{
return This.RegisterAsyncFunction(x => { calculationFunc(x); return Unit.Default; }, scheduler);
}
你也可以ObserveOnDispatcher()
在UIThread上运行代码。
实际上,您不需要这样做,RxUI已经保证Register*
的结果会返回到UI线程。
我切换到'RegisterAsyncFunction',返回一个虚拟值。稍后,我在ReactiveAsyncCommand上找到了一个'AsyncCompletedNotification'。我没有尝试,但它看起来像一个可能的解决方案? – Vegar
虽然它丢失了返回方法的数据,但最好使用Register * –
的返回结果,在这种情况下,不会有返回值丢失。但是返回'IObservable'的'RegisterAsyncAction'在任何情况下都更好。谢谢! – Vegar