0

我在 ASP.NET 中有一个页面,我需要从页面加载异步调用服务器端函数,然后重定向到另一个页面。我的电话如下:

公共课第1页

Private Delegate Sub AsyncCallerDelegate(ByVal par1 As Integer, ByVal par2 As Integer)

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.DoSomeStuff()
    Me.AsyncCall()
    Response.Redirect("anotherPage.aspx")
End Sub

Private Sub DoSomeStuff() '做一些事情... End Sub

Private Sub AsyncCall()
    Try
        Dim caller As New AsyncCallerDelegate(AddressOf AsyncMethod)
        caller.BeginInvoke(par1, par2, Nothing, Nothing)
    Catch ex As Exception
        Me.LogError("Error calling asynchronous method AsyncMethod.")
    End Try
End Sub

Public Sub AsyncMethod(ByVal par1 As Integer, ByVal par2 As Integer)
    Class1.DoSomeOtherStuff(par1, par2)
End Sub

结束类

Class1.DoSomeOtherStuff 中的代码未执行,也未记录错误。但是,重定向已完成,并且 DoSomeStuff() 方法也将运行。我异步调用的方法(Class1.DoSomeOtherStuff)需要 50 秒才能运行。我认为重定向以某种方式在完成运行之前杀死了代表,但我不确定......

谢谢!!

4

0 回答 0