2011-03-16 39 views
0

您好,我使用多次不同参数值调用Async方法,在完成的事件中给出相同的结果。在Silverlight中多次调用异步方法问题

client.ListAllLookupValuesByTypeCompleted += client_ListAllAddressFormatCompleted; 
client.ListAllLookupValuesByTypeAsync("AddressFormat"); 

client.ListAllLookupValuesByTypeCompleted += client_ListAllPhoneFormatCompleted; 
client.ListAllLookupValuesByTypeAsync("PhoneFormat"); 



void client_ListAllAddressFormatCompleted(object sender, ListAllLookupValuesByTypeCompletedEventArgs e) 
     { 
      cmbAddressFormat.ItemsSource = e.Result; 
     } 


void client_ListAllPhoneFormatCompleted(object sender, ListAllLookupValuesByTypeCompletedEventArgs e) 
     { 
      cmbPhonePrintFormat.ItemsSource = e.Result; 
     } 

请帮帮我。 谢谢。

+0

当我遇到同样的问题时,我扩展了服务客户端类(它是一个部分类)并添加了我自己的方法,它们使用内部的BeginSomeOperation和EndSomeOperation方法。每次都不可能创建新的服务实例,因为我需要使用会话。 – vorrtex 2011-03-16 08:38:46

+0

当有人回答您的问题时,请点击该答案旁边的绿色勾号。谢谢。 – jumbo 2011-03-18 23:11:41

回答

1

您可以创建client的新实例。

... 
var client = new XyzClient(); 
client.ListAllLookupValuesByTypeCompleted += client_ListAllAddressFormatCompleted; 
client.ListAllLookupValuesByTypeAsync("AddressFormat"); 

client = new XyzClient(); 
client.ListAllLookupValuesByTypeCompleted += client_ListAllPhoneFormatCompleted; 
client.ListAllLookupValuesByTypeAsync("PhoneFormat"); 
... 


void client_ListAllAddressFormatCompleted(object sender, ListAllLookupValuesByTypeCompletedEventArgs e) 
{ 
    cmbAddressFormat.ItemsSource = e.Result; 
} 


void client_ListAllPhoneFormatCompleted(object sender, ListAllLookupValuesByTypeCompletedEventArgs e) 
{ 
    cmbPhonePrintFormat.ItemsSource = e.Result; 
} 

另一种解决方案是在第一个处理程序中进行第二次调用(可能会创建新的客户机实例)。

+0

感谢您的宝贵回复。 – sag 2011-03-16 08:59:21

+0

它以这种方式工作,谢谢。 – sag 2011-03-16 09:03:03

+0

@sag不客气!如果您接受该答案,我将不胜感激;-)谢谢。 – jumbo 2011-03-16 10:00:44