我在ASP.NET中有一个页面,我需要从页面加载异步调用服务器端函数,然后重定向到另一个页面。 我的电话如下:
Public Class Page1
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() '做些什么...... 结束子
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秒才能运行。 我想某种方式重定向是在它完成运行之前杀死委托,但我不确定......
谢谢!