1

我在下面的代码中有一个 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");
            }

        };
    }

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

4

2 回答 2

0

你在这里有一个架构问题,除非你有充分的理由,否则服务不应该调用异步请求(也许调用一些并行的东西。只需同步调用你的服务器端代码。

一个服务入口点有它自己的处理线程,它应该是在服务端启动和结束请求响应过程的那个。您所做的是在服务端调用异步方法,使处理请求的线程完成他的工作。所以你要么让这个线程等待,要么在他身上执行整个逻辑而不调用异步方法,卡皮什?

于 2012-10-05T07:15:10.453 回答
0
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
于 2012-10-22T06:43:27.060 回答