已经有一段时间了,因为我完全写了任何代码,所以我有点生疏了。我最近开始编写一个机器人,目前我仍然坚持将异步函数中的数组转换为常规数组,以便在另一个函数中进行解析。
Private Async Function getmsgs(ByVal num As Integer) As Task(Of Array)
Dim msgids As Array = Nothing
Try
Dim msg = Await Libx.DownloadMessages(num)
'starting loop to pull each message and assign to array
For i As Integer = msg.Count - 1 To 0 Step -1
If (msg(i).Id > 0) Then
msgids(i) = msg(i).Id
End If
Next
'returning array
Return msgids
Catch ex As Exception
Return msgids
End Try
End Function
Private Sub deletemsgs(ByVal ids As Array)
If Not ids(0) = Nothing Then
'incase library failed to retrieve messages
Try
For i As Integer = ids.Length - 1 To 0 Step -1
'function called per item in array
libx.DeleteMessages(ids(i))
Next
Catch ex As Exception
End Try
End If
End Sub
尝试调用deletemsgs(getmsgs(argint))时会出现此问题。 我收到了错误消息"类型'任务(数组)的值'无法转换为'数组'。我已经通过几个论坛搜索了我能想到的每个相关搜索词。任何帮助将不胜感激,提前欢呼
答案 0 :(得分:2)
您需要await
async
个功能。
一个例子是:
Dim arr As Array() = await getmsgs(1)
这需要在async
函数内部才能正常工作。