Wcf 有多个Dispatcher.BeginInvoke可以吗?

Wcf 有多个Dispatcher.BeginInvoke可以吗?,wcf,silverlight,binding,wcf-binding,Wcf,Silverlight,Binding,Wcf Binding,我只是silverlight和WCF的新手。我看到一篇很好的文章http://www.netfxharmonics.com/2008/11/Understanding-WCF-Services-in-Silverlight-2 Miguel A.Castro教授手动添加WCF 在本例中,它使用Dispatcher.BeginInvoke将服务返回的文本写入silverlight UI中的文本块 AsyncCallback asyncCallBack = delegate(IAsyn

我只是silverlight和WCF的新手。我看到一篇很好的文章http://www.netfxharmonics.com/2008/11/Understanding-WCF-Services-in-Silverlight-2 Miguel A.Castro教授手动添加WCF

在本例中,它使用Dispatcher.BeginInvoke将服务返回的文本写入silverlight UI中的文本块

       AsyncCallback asyncCallBack = delegate(IAsyncResult result)
        {
            List<Person> person = ((IPersonService_list)result.AsyncState).EndGetPersonData(result);
            this.Dispatcher.BeginInvoke(delegate
            {
                spMain.Children.Add(new TextBlock
                {
                    Text = person[0].FirstName + person[0].LastName + person[0].City + person[0].State
                });

            });
        };
我需要使用同一服务填充多个控件。似乎我不允许在BeginInvoke方法中调用另一个函数。有多个BeginInvoke方法的最佳方法是什么?这会消耗大量资源吗


谢谢,

一种可行的方法是:根据WCF服务调用的结果构建一个完整的封闭UIElement结构,然后使用一个对Dispatcher.BeginInvoke的调用,并将该结构添加到SPUIElement中。例如:

StackPanel sp = new StackPanel();
TextBlock tb1 = new TextBlock({
    Text=person[0].FirstName + person[0].LastName
});
sp.Children.Add(tb1);
TextBlock tb2 = new TextBlock({Text="AND SO ON Use this pattern to add UIElements to the stackpanel."});

sp.Children.add(tb2);

//now - add the StackPanel which holds other UIElements to spMain.

this.Dispatcher.BeginInvoke(delegate(){
    spMain.Children.Add( sp );
}); 

谢谢,这是一个很好的建议!