call a Async Method multiple times problem in silverlight

本小妞迷上赌 提交于 2020-01-06 05:47:47

问题


Hi i am calling a Async method with different parameter value multiple times giving same result in completed event.

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;
        }

please help me. Thanks.


回答1:


You can create new instance of 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;
}

Another solution would be to make the second call in the handler of the first one (probably creating new client instance anyway).



来源:https://stackoverflow.com/questions/5322237/call-a-async-method-multiple-times-problem-in-silverlight

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!