异步任务完成后的asp.net更新标签

时间:2019-05-12 19:40:41

标签: asp.net vb.net async-await

以下代码可以很好地执行,但是即使放置断点表明t.Completed调用也不会更新标签文本。返回lblMsg.InnerHtml =“请访问您的电子邮件以重设密码”。 我显然对异步还不太满意;-)。谢谢。

Private Async Function ResetPassword() As Task
    Dim API_KEY As String = "AIzaSyD9iS5-Zp6fP5phEOq8HVUf5cU9*****"
    Try
        Dim email As String = txtEmail.Text
        Dim firebaseAuth = New FirebaseAuthProvider(New FirebaseConfig(API_KEY))

        Await firebaseAuth.SendPasswordResetEmailAsync(email).ContinueWith(
            Function(t)
                If t.IsFaulted Then
                    Return errMsg.InnerHtml = t.Exception.InnerException.Message
                End If
                If t.IsCanceled Then Return errMsg.InnerHtml = "Canceled"
                If t.IsCompleted Then Return lblMsg.InnerHtml = "Please access your email in order to reset your password"
                Return lblMsg.InnerHtml = "Unexpected error."
            End Function)

    Catch ex As FirebaseAuthException
        errMsg.InnerHtml = ex.GetBaseException.Message
    End Try
    Return
End Function

呼叫代码

Private Sub btnResetPWD_Click(sender As Object, e As EventArgs) Handles btnResetPWD.Click
    Dim LoadTask As New PageAsyncTask(AddressOf ResetPassword)
    Page.RegisterAsyncTask(LoadTask)
End Sub

0 个答案:

没有答案