Live SDK:await client.GetAsync(“me / skydrive / files?filter = folders”)不会返回

时间:2013-07-04 10:56:22

标签: vb.net windows-phone-8 async-await live-sdk

我正在为我的应用程序开发备份功能,它应该检查所需的文件夹是否已经存在,否则创建它。

由于我使用VB.Net,我无法使用GetCompleted事件(仅在C#中可用,我没有经验)。

我在FolderExistsOrCreate函数中的当前代码是这样的:

    Private Async Function FolderExistsOrCreate(ByVal Name As String) As System.Threading.Tasks.Task(Of String)
        Dim ID As String = Nothing
        Dim firstRecheck = True
ReCheck:
        Try
            _message = "Looking for folder..."
            NotifyPropertyChanged("Message")
            NotifyPropertyChanged("SkyDrive")
            _client = New LiveConnectClient(_session)
 'it stops here and does not go further
            Dim res = Await _client.GetAsync("me/skydrive/files?filter=folders,albums")
            Dim folderData As Dictionary(Of String, Object) = DirectCast(res.Result, Dictionary(Of String, Object))
            Dim folders As List(Of Object) = DirectCast(folderData("data"), List(Of Object))

            For Each item As Object In folders
                Dim folder As Dictionary(Of String, Object) = DirectCast(item, Dictionary(Of String, Object))
                If folder("name").ToString = Name Then
                    ID = folder("id").ToString()
                    _message = "Folder exists..."
                    NotifyPropertyChanged("Message")
                    NotifyPropertyChanged("SkyDrive")
                End If
            Next

            If ID = Nothing Then
                If firstRecheck = False Then
                    _message = "Creating folder failed..."
                    NotifyPropertyChanged("Message")
                    NotifyPropertyChanged("SkyDrive")
                    Return Nothing
                End If
                _message = "Creating folder..."
                NotifyPropertyChanged("Message")
                NotifyPropertyChanged("SkyDrive")
                Dim newFolderData As New Dictionary(Of String, Object)
                newFolderData.Add("name", Name)
                _client = New LiveConnectClient(_session)
                res = Await _client.PostAsync("me/skydrive", newFolderData)
                firstRecheck = False
                GoTo ReCheck
            End If
            Return ID
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

该函数位于我构建的包含SignIn按钮的控件中,我将SkyDrive类作为属性添加到控件中,它使用的_session是使用SignIn按钮创建的会话。

我获得了一个有效的客户端,但是所有的GetAsync函数都会让应用程序暂停,没有任何异常。分配的范围确实包含“skydrive_update”,因此授予访问权限以创建文件夹,但代码甚至没有那么远。

我在MSDN上的Live SDK论坛和论坛中搜索了任何类型的答案,但我能找到的只是使用GetCompleted方法的C#函数。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我猜你的调用堆栈越来越远,你打电话给WaitResult,从而导致deadlock that I describe on my blog