0

Silverlight アプリケーションを使用して Web リソースを開発しています。ここでは、非同期操作である ServiceProxy.BeginExecute メソッドを使用していますが。今、私はCRMサービスのBeginexecuteを呼び出すメソッドBを内部的に呼び出すメソッドAを呼び出す必要がある状況にあり、BeginExecuteメソッドが完了したときに実行するデリゲートを与えます。BeginExecute メソッドは Asynch であるため、応答が返される前にメインスレッドが返されます。BeginExecute が完了するまでメインスレッドを保持したい。

どうすればこれを実行できますか??

4

2 に答える 2

0

CRM Silverlight の開発では、Microsoft のリアクティブ フレームワークを使用しています。ごく一部しか使用していませんが、CRM を呼び出すすべての関数を IObservable にし、それをサブスクライブして結果をリッスンします。クールなことは、複数のイベントを連鎖させて最終結果をサブスクライブできることです。これにより、すべてが完了するまで待機します。

これは簡単な呼び出しの例です

public static IObservable<ProductGroup> RetrieveProductGroupByProductID(IOrganizationService service, Guid productID)
        {
            var res = RXCRMMethods.Retrieve(service, "product", productID, new ColumnSet() { Columns = new ObservableCollection<string> { "py3_productgroup" } });

            return Observable.Create<ProductGroup>(observer =>
            {
                try
                {
                    res.Subscribe(e =>
                    {
                        ProductGroup pg = new ProductGroup 
                        { 
                            ProductGroupId = e.GetAttributeValue<EntityReference>("py3_productgroup").Id
                        };
                        observer.OnNext(pg);
                    },
                        ex =>
                        {
                            observer.OnError(ex);
                        });
                }
                catch (Exception ex)
                {
                    observer.OnError(ex);
                }
                return () => { };
            });

        }

そして、これが複数の呼び出しにサブスクライブする方法です

var LoadQRY = from MatExResult in MaterialExclusionsFactory.GetMaterialExclusionsForOpportunity(this.Config.CrmService, this.OpportunityID)
                                  from result in QuoteLineItemFactory.RetrieveQuoteLineItems(Config.CrmService, this)
                                  from crateResult in QuotePackingCrateFactory.GetOneOffCratesForQuote(this.Config.CrmService, this.QuoteId)
                                  from StaticResult in QuoteLineItemFactory.RetrieveStaticQuoteLineTypes(this.Config.CrmService,this)
                                  select new {  MatExResult,result,crateResult,StaticResult };

                    LoadQRY.Subscribe(LoadResult =>
                        {
                           //Do something
                         },ex=>
                         {
                             //Catch errors here
                        });
于 2013-09-27T07:09:45.187 に答える