我在 .Net 4.0 C# 应用程序中对一个 Web 服务进行了两次异步调用。这些是通过使用 AutoResetEvent 来控制的WaitOne()
。
在我的本地机器上,这是按预期工作的。但是当我将它部署在服务器中时,第二步的成功处理程序在第一次调用中被调用。
需要进行哪些更改才能使线程正常运行?
if (userID != null)
{
AddressBookRequest req = new AddressBookRequest
{
contactsSearchCriteria = new ContactsSearchCriteria
{
searchUserID = userID.Trim()
},
HeaderParams = new HttpHeaderParms
{
UserId = userID.Trim(),
UserPrincipalName = userID.Trim() ,
ContentType = "application/xml"
}
};
lookupServicesAssociate.SearchContactDetailsAsync(req);
autoRestEvent = new AutoResetEvent(false);
lookupServicesAssociate.SearchContactDetailsCompleted +=
new EventHandler<ServiceResponseEventArgs<ContactDetailsPreview[]>>(AssociateSearchContactDetailsCompleted);
autoRestEvent.WaitOne();
}
if (reportsToUserID != null)
{
AddressBookRequest req1 = new AddressBookRequest
{
contactsSearchCriteria = new ContactsSearchCriteria
{
searchUserID = reportsToUserID.Trim()
},
HeaderParams = new HttpHeaderParms
{
UserId = reportsToUserID.Trim(),
UserPrincipalName = reportsToUserID.Trim(),
ContentType = "application/xml"
}
};
lookupServiceReports.SearchContactDetailsAsync(req1);
lookupServiceReports.SearchContactDetailsCompleted +=
new EventHandler<ServiceResponseEventArgs<ContactDetailsPreview[]>>(ReportsToAssociateSearchContactDetailsCompleted);
autoRestEvent.WaitOne();
}