这可能是一个愚蠢的问题。但是当我从 Live SDK 示例中修改一个示例时,遇到了一个奇怪的问题。
我在想根本原因是异步函数 GetAll() 被同步使用。
以下是代码片段,我将问题作为注释。提前致谢!
class SkyeDriveViewModel: INotifyPropertyChanged
{
private List<SkyDriveItem> folderList = null;
public List<SkyDriveItem> FolderList
{
get { return folderList; }
private set
{
if (value != folderList)
{
folderList = value;
NotifyPropertyChanged("FolderList");
}
}
}
private async void GetAll(string desiredPath)
{
FolderList = new List<SkyDriveItem>();
this.liveClient = new LiveConnectClient(SkyDrivePage.Session);
try
{
LiveOperationResult operationResult = await this.liveClient.GetAsync(desiredPath);
dynamic result = operationResult.Result;
dynamic items = result.data;
foreach (dynamic item in items)
{
SkyDriveItem newItem = new SkyDriveItem(item);
if (newItem.IsFolder)
{
FolderList.Add(newItem);
}
}
}
catch (LiveConnectException e)
{
}
//**till here, FolderList was assigned**
}
public void InitList()
{
Debugger.Log();
GetAll(SKYDRIVEINITPATH);
Debugger.LogWhen(eDebugger.LogTiming.Exit);
//**till here, FolderList had zero item**
}
}