79110686

Date: 2024-10-21 15:21:03
Score: 3
Natty:
Report link

Wow, Albert, this is above and beyond, can't thank you enough for taking the time. The email analogy might be a common thing in ASP.NET circles but it's bloody brilliant, best description I've seen, thanks for that too.

After some trouble I decided to try your code verbatim and from my test page removed the master page dependency and pasted in your code, the page shows the zero but it never changes because the session variable in the tick event is always zero. :o/

Details of my overall setup:

The first page of my app is a login page. Currently it simply redirects to my test page using Response.Redirect("TestForm.aspx", True) in it's _LoadComplete event.

Early on with this project Session variables weren't working in VisualStudio, I'd set it one place but it wasn't available in another, though they worked when I published to the webserver. After turning on the "ASP.NET State Service" and updating my web.config with mode="StateServer" I haven't had a problem since.

But, something isn't right, the result on the page shows the zero, but it doesn't change and the Session variable is always zero in the _Tick event. The code below is your code with only the two Debug.Print lines added and the interval of the loop reduced from 20 to 5. When I run this code I'm getting this result in the Immediate window, with the "Exception thrown:" line being the redirection to the test page, of course:

Exception thrown: 'System.Threading.ThreadAbortException' in mscorlib.dll
Session var in the loop: 1
iStep in Timer1_Tick: 0
Session var in the loop: 2
iStep in Timer1_Tick: 0
Session var in the loop: 3
iStep in Timer1_Tick: 0
Session var in the loop: 4
iStep in Timer1_Tick: 0
Session var in the loop: 5
iStep in Timer1_Tick: 0
iStep in Timer1_Tick: 0
iStep in Timer1_Tick: 0
.
.
.

What am I missing?!

Thanks again

XML:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="TestForm.aspx.vb" Inherits="TekntypeUpDownLoad.TestForm" %>

<html xmlns="http://www.w3.org/1999/xhtml">
    <body>
        <form id="TstForm" runat="server">

            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

            <asp:Button ID="cmdStart" runat="server" Text="Start"
                OnClick="cmdStart_Click" />

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    Current Progress:
                    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>

                    <asp:Timer ID="Timer1" runat="server"
                        Enabled="False"
                        Interval="1000"
                        OnTick="Timer1_Tick">
                    </asp:Timer>

                </ContentTemplate>
            </asp:UpdatePanel>
        </form>
    </body>
</html>

VB:

Public Class TestForm
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub cmdStart_Click(sender As Object, e As EventArgs)

        Session("Progress") = 0

        Dim MyThread As New Threading.Thread(
        Sub()

            For i = 1 To 5
                Session("Progress") = i
                System.Threading.Thread.Sleep(1000)
                Debug.Print("Session var in the loop: " & Session("Progress"))
            Next

        End Sub)

        MyThread.Start()
        Timer1.Enabled = True

    End Sub

    Protected Sub Timer1_Tick(sender As Object, e As EventArgs)

        Dim iStep As Integer = Session("Progress")

        Debug.Print("iStep in Timer1_Tick: " & iStep)

        Label1.Text = iStep

        If iStep >= 5 Then
            Timer1.Enabled = False
        End If

    End Sub
End Class
Reasons:
  • Blacklisted phrase (0.5): thank you
  • Blacklisted phrase (0.5): thanks
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Self-answer (0.5):
  • Looks like a comment (1):
  • Low reputation (1):
Posted by: Ken Krugh