等待可观察的订阅完成

时间:2014-01-30 15:00:56

标签: c# observablecollection race-condition observable

有一些可观察的问题。目前正在开展一个充满了它们的项目,目前它们会导致相当多的竞争条件。

有没有办法对应用程序进行“锁定”,直到所述observable收到它试图收集的信息为止?

以下是订阅:

serviceLookup.GetAvailableBalance(this.AppointmentGroup)
                .Take(1)
                .Subscribe(ab =>
                {
                        if (ab.Error != null)
                        {
                            SingletonProvider.EventAggregator.Publish(new Error
                            {
                                Exception = ab.Error,
                                Description = "Failed to validate the voucher."
                            });

                            return;
                        }

                        if (!string.IsNullOrEmpty(ab.Result.First().Message))
                        {
                            SingletonProvider.EventAggregator.Publish(new Error
                            {
                                Exception = new Exception("Voucher Validation Error"),
                                Description = ab.Result.First().Message
                            });

                            return;
                        }

                        ObservableCollection<AvailableBalance> balance = ab.GetResult<ObservableCollection<AvailableBalance>, GetAvailableBalanceCompletedEventArgs>();
                });

GetAvailable balance将调用服务以返回所需的信息。我希望这个电话在完成之前完成。任何人都可以指导我朝正确的方向发展吗?

0 个答案:

没有答案