Saturday, October 6, 2012

Asynchronous call in one more Asynchronous call not working in silverlight

Asynchronous call in one more Asynchronous call not working in silverlight

I have a UI view lossreport.xaml in that below code is there

    LossReportTowGlassServiceClient wcf = new LossReportTowGlassServiceClient();             wcf.HouseholdSearchCompleted += (o, ev) =>             {                 string a = errorMessg.ToUpper();         //Code to work with ev             };             wcf.HouseholdSearchAsync(lossDate, txtPolicyNumber.Text, errorMessg); 

in service.svc page

             try                 {                     policyinq.retrieveHouseHoldPoliciesCompleted += new   retrieveHouseHoldPoliciesCompletedEventHandler(policyinq_retrieveHouseHoldPoliciesCompleted);                      policyinq.retrieveHouseHoldPoliciesAsync(reqh, searchCriteria, lossdate, true, string.Empty, string.Empty);                     break;                 }                 catch (Exception ex)                 {                     Logger.Exceptions("", "HouseholdSearch", ex);                     errorToSend = "Household error";                 }       void policyinq_retrieveHouseHoldPoliciesCompleted(object sender,   retrieveHouseHoldPoliciesCompletedEventArgs e)     {         {             if (e.transactionNotification != null && e.transactionNotification.transactionStatus == TransactionState.S)             {              }             else             {                 ErrorHandling.ErrorSend(e.transactionNotification, "HouseHold");             }          };     } 

now before retrieveHouseHoldPolicies is completed HouseholdSearchCompleted event is fired.How to make it wait

Answers & Comments...

Answer: 1

You have an architectural issue here, The service should not invoke async request unless you go ta good reason (maybe invoke some paralleled stuff. Just invoke your server side code synchronously.

A service entry point got it's own handler thread, it should be the one who starts and end the request response process on service side. what you do is call an async method on service side making the thread that handle the request finish his job. So you either make this thread wait or execute the entire logic on him without calling async method, kapish?

by : Chen Kinnrothttp://stackoverflow.com/users/67505




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog