I'm guessing that further up your call stack, you have a call to Wait
or Result
, thus causing the deadlock that I describe on my blog.
Live SDK: await client.GetAsync("me/skydrive/files?filter=folders") does not return
-
02-06-2022 - |
Question
I'm working on a backup function for my app, and it's supposed to check if the needed folder already exists, otherwise create it.
Since I'm using VB.Net I cant use the GetCompleted event (only available in C#, which I have no experience with).
My current code in the FolderExistsOrCreate function is like this:
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
The function is in a control I've built that contains the SignIn button, and I have added my SkyDrive class as a property to the control, and the _session it uses is the session created with the SignIn button.
I get a valid client, but all the GetAsync functions makes the app halt there without any exception. The assigned scopes does include "skydrive_update", so access is granted to create the folder too, but the code doesn't even go that far.
I've searched the Live SDK forums and the forums at MSDN for any type of answer, but all I can find are C# functions using the GetCompleted method.
Any ideas?
Solution