I have a website that does some potentially long-running things that should respond and update the timer for the user.
My solution was to create a state machine on a page with a hidden value and some session values.
I have this on the aspx side:
<asp:Timer ID="Timer1" runat="server" Interval="1600" /> <asp:HiddenField runat="server" ID="hdnASynchStatus" Value="" />
And my code looks something like this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load PostbackStateEngineStep() UpdateElapsedTime() End Sub Private Sub PostbackStateEngineStep() If hdnASynchStatus.Value = "" And Not CBool(Session("WaitingForCallback")) Then Dim i As IAsyncResult = {...run something that spawns in it own thread, and calls ProcessCallBack when it done...} Session.Add("WaitingForCallback", True) Session.Add("InvokeTime", DateTime.Now) hdnASynchStatus.Value = "WaitingForCallback" ElseIf CBool(Session("WaitingForCallback")) Then If Not CBool(Session("ProcessComplete")) Then hdnASynchStatus.Value = "WaitingForCallback" Else 'ALL DONE HERE 'redirect to the next page now response.redirect(...) End If Else hdnASynchStatus.Value = "DoProcessing" End If End Sub Public Sub ProcessCallBack(ByVal ar As IAsyncResult) Session.Add("ProcessComplete", True) End Sub Private Sub UpdateElapsedTime() 'update a label with the elapsed time End Sub
source share