Silverlight 4.0 使用不同参数Silverlight 4.0多次调用异步方法
我调用的异步方法只有一个参数,它将根据参数返回结果。我使用不同的参数值多次调用该方法,但在完成的事件中,我得到的所有参数值都相同Silverlight 4.0 使用不同参数Silverlight 4.0多次调用异步方法,silverlight-4.0,Silverlight 4.0,我调用的异步方法只有一个参数,它将根据参数返回结果。我使用不同的参数值多次调用该方法,但在完成的事件中,我得到的所有参数值都相同 client.ListAllLookupValuesByTypeCompleted += client_ListAllAddressFormatCompleted; client.ListAllLookupValuesByTypeAsync("AddressFormat"); client.ListAllLookupValuesByTypeCompleted +=
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;
}
但在e.Result中得到相同的值
任何建议。谢谢。您的方法可能会根据第一个参数返回不同的值,但无论发送什么,每次都会同时调用两个处理程序。如果这是一个标准的webservice引用,那么您应该看到一个可供您使用的object userState参数,该参数可用于确定要执行的操作
client.ListAllLookupValuesByTypeCompleted += client_ListAllLookupValuesCompleted;
client.ListAllLookupValuesByTypeAsync("AddressFormat", true);
client.ListAllLookupValuesByTypeAsync("PhoneFormat", false);
void client_ListAllLookupValuesCompleted(object sender, ListAllLookupValuesByTypeCompletedEventArgs e)
{
// e.UserState will either be false or true
if ((bool)e.UserState)
cmbAddressFormat.ItemsSource = e.Result;
else
cmbPhonePrintFormat.ItemsSource = e.Result;
}