开发者

Calling a async method multiple times with different parameter Silverlight 4.0

开发者 https://www.devze.com 2023-02-17 09:56 出处:网络
I am callin开发者_开发技巧g a async method having a single parameter, It will return me the result according to parameter. I am calling that method more than one time with different parameter value, b

I am callin开发者_开发技巧g a async method having a single parameter, It will return me the result according to parameter. I am calling that method more than one time with different parameter value, but in Completed event i am getting the same value for all.

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

But getting same value in e.Result.

any suggetions. Thanks.


Your method may return a different value based on the first parameter, but both handlers will be called at the same time every time, regardless of what you send it. If this is a standard webservice reference, then you should see an object userState parameter available for you and this can be used to determine what to do.

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

精彩评论

暂无评论...
验证码 换一张
取 消