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