Wcf 一个或多个异步调用中的异步调用在silverlight中不工作

Wcf 一个或多个异步调用中的异步调用在silverlight中不工作,wcf,silverlight,Wcf,Silverlight,我有一个UI视图lossreport.xaml,下面的代码就在那里 LossReportTowGlassServiceClient wcf = new LossReportTowGlassServiceClient(); wcf.HouseholdSearchCompleted += (o, ev) => { string a = errorMessg.ToUpper(); //Code

我有一个UI视图lossreport.xaml,下面的代码就在那里

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

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

        };
    }

现在,在RetrieveHouseholdPolicys完成之前,HouseholdSearchCompleted事件被触发。如何让它等待

这里有一个体系结构问题,除非您有充分的理由(可能调用一些并行的东西),否则服务不应该调用异步请求。只需同步调用服务器端代码即可

服务入口点有自己的处理程序线程,它应该是在服务端启动和结束请求-响应过程的线程。您要做的是在服务端调用一个异步方法,使处理请求的线程完成其工作。因此,您可以让该线程等待,或者在其上执行整个逻辑,而不调用异步方法卡皮什

using System.Threading;
ManualResetEvent _wait = new ManualResetEvent(false);
_wait.Set();//In completed event
_wait.WaitOne();//After the event is completed WaitOne will wait untill the _wait is set with value