将C#PageAsyncTask()转换为VB.Net等效文件时出现问题

将C#PageAsyncTask()转换为VB.Net等效文件时出现问题,c#,vb.net,async-await,delegates,c#-to-vb.net,C#,Vb.net,Async Await,Delegates,C# To Vb.net,尝试将C#函数转换为VB.Net等效函数时出现编译错误。C#中的PageAsyncTask需要一个任务输入,但在VB.Net中它需要(任务的)Func。我所能找到的在线转换器中没有一个能正确翻译语言。 错误是: “任务”类型的值无法转换为“任务的函数” Dim t As New PageAsyncTask(performCodeExchange) 不确定如何继续(我猜我需要定义一个事件?)。 这是原始的C代码 Dim t As New PageAsyncTask(performCodeExch

尝试将C#函数转换为VB.Net等效函数时出现编译错误。C#中的PageAsyncTask需要一个任务输入,但在VB.Net中它需要(任务的)Func。我所能找到的在线转换器中没有一个能正确翻译语言。 错误是: “任务”类型的值无法转换为“任务的函数”

Dim t As New PageAsyncTask(performCodeExchange)
不确定如何继续(我猜我需要定义一个事件?)。 这是原始的C代码

Dim t As New PageAsyncTask(performCodeExchange)
以及代码转换为什么:

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If True Then
            AsyncMode = True
            If Not dictionary.ContainsKey("accessToken") Then
                If Request.QueryString.Count > 0 Then
                    Dim response = New AuthorizeResponse(Request.QueryString.ToString())
                    If response.State IsNot Nothing Then
                        If oauthClient.CSRFToken = response.State Then
                            If response.RealmId IsNot Nothing Then
                                If Not dictionary.ContainsKey("realmId") Then
                                    dictionary.Add("realmId", response.RealmId)
                                End If
                            End If

                            If response.Code IsNot Nothing Then
                                authCode = response.Code
                                output("Authorization code obtained.")
                                Dim t As New PageAsyncTask(performCodeExchange)
                                Page.RegisterAsyncTask(t)
                                Page.ExecuteRegisteredAsyncTasks()
                            End If
                        Else
                            output("Invalid State")
                            dictionary.Clear()
                        End If
                    End If
                End If
            Else
                homeButtons.Visible = False
                connected.Visible = True
            End If
        End If
    End Sub
Dim t As New PageAsyncTask(performCodeExchange)
问题领域:

Dim t As New PageAsyncTask(performCodeExchange)
任务函数是performCodeExchange,它返回一个任务

Dim t As New PageAsyncTask(performCodeExchange)
    Public Async Function performCodeExchange() As Task
    output("Exchanging code for tokens.")
    Try
        Dim tokenResp = Await oauthClient.GetBearerTokenAsync(authCode)
        If Not _dictionary.ContainsKey("accessToken") Then
            _dictionary.Add("accessToken", tokenResp.AccessToken)
        Else
            _dictionary("accessToken") = tokenResp.AccessToken
        End If

        If Not _dictionary.ContainsKey("refreshToken") Then
            _dictionary.Add("refreshToken", tokenResp.RefreshToken)
        Else
            _dictionary("refreshToken") = tokenResp.RefreshToken
        End If

        If tokenResp.IdentityToken IsNot Nothing Then
            idToken = tokenResp.IdentityToken
        End If
        If Request.Url.Query = "" Then
            Response.Redirect(Request.RawUrl)
        Else
            Response.Redirect(Request.RawUrl.Replace(Request.Url.Query, ""))
        End If
    Catch ex As Exception
        output("Problem while getting bearer tokens.")
    End Try
End Function
为了彻底起见,最初的C代码:

Dim t As New PageAsyncTask(performCodeExchange)

我不知道在这里该做什么-请一名代表进来?如何使用任务(在VB.Net中)完成此操作

执行
PageAsyncTask时t=new-PageAsyncTask(performCodeExchange)
在C#中,隐式创建指向
performCodeExchange
方法的委托,并将其传递给
PageAsyncTask
的构造函数

Dim t As New PageAsyncTask(performCodeExchange)
现在,VB中的语句
Dim t As New PageAsyncTask(performCodeExchange)
有了细微的不同。VB中的函数可以在没有括号的情况下求值,因此这相当于
Dim t As New PageAsyncTask(performCodeExchange())
。这意味着
PageAsyncTask
的构造函数接收
performCodeExchange
的评估结果,而不是方法的委托

Dim t As New PageAsyncTask(performCodeExchange)
要在VB中获取代理,可以使用
AdressOf
关键字。代码应重写为:

Dim t As New PageAsyncTask(performCodeExchange)
Dim t As New PageAsyncTask(AddressOf performCodeExchange)

我不敢相信我没有看到这一点(我希望能够永远从VB.Net运行,然后被拖了回来)。杰出的谢谢