【发布时间】:2011-07-06 16:54:59
【问题描述】:
我正在开发一个 Windows Phone 7 应用程序,并且我使用 Windows Live 身份验证来访问用户联系人。我有一个网络服务,方法如下:
public IEnumerable<LiveIDContact> GetContactsInformationYield(string LocationID, string DelegationToken)
{
string uriTemplate = "https://livecontacts.services.live.com/@L@{0}/rest/LiveContacts/Contacts";
var xdoc = WindowsLiveContactAPIRequest(LocationID, DelegationToken, uriTemplate);
var contacts = (from contact in xdoc.Descendants("Contact")
select contact).ToArray();
foreach (var con in contacts)
{
RetrieveCID(LocationID, DelegationToken, con);
LiveIDContact c = new LiveIDContact()
{
ID = con.Element("ID").Value,
DisplayName = con.Element("Profiles").Element("Personal").Element("DisplayName").Value,
CID = (con.Element("CID") != null ? con.Element("CID").Value : "")
};
yield return c;
}
}
我如何在应用程序中调用方法:
public void GetContactInformationAsync()
{
LiveIDClient.GetContactsInformationYieldAsync(LocationID, ConsentToken);
}
这是问题所在,当我调用此方法并等待完成事件时。更新我的应用程序中的联系人列表需要 4 到 5 分钟。(性能问题)。有没有办法在每个收益回报上发生事件?所以我可以从那个事件中更新我的列表?
我在任何地方都找不到答案,所以希望有人知道答案。
【问题讨论】:
-
您在 GetContactInformationAsync 方法中调用 GetContactsInformationYieldAsync。您尚未发布该方法,目前没有调用 GetContactsInformationYield。
-
我正在调用 GetContactsInformationYieldAsync(LocationID, ConsentToken);异步部分是由visual studio添加的,因为它是windows phone,每个服务调用都是异步的。方法调用有效,唯一的问题是加载所有联系人需要 4 到 5 分钟。
标签: windows-phone-7 return webservice-client yield