locked
timer event overflows RRS feed

  • Question

  • User297437924 posted

    I have a website that lets the user save an object.   This 'save' takes a long time to execute.   I put a save icon on the menu.   The icon goes to a web form.   The page displays an animated hourglass to show time passing.    In the Form_Load command, I put a timer that I want to execute only once.   In the timer event, I put 'timer1.enabled = false'.   Then I call the lengthy save routine (in that event).   I have the timer interval set for 100.  (I don't call the 'save' event in the form-load event because the form would not appear until the lengthy operation is over.)

    But I get an overflow.   I think what is happening is that the timer1 event takes so long that it fires more events, even though 'timer1.enabled' was set to false.   

    Is there a way around this?

    Sunday, March 29, 2020 11:16 AM

Answers

  • User475983607 posted

    The timer fires every 100 ms on the server.  Why?  What are you timing?   How long a process runs?   Is there anyway you can provide enough sample code the community can run to reproduce the same issue?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 29, 2020 11:39 PM

All replies

  • User475983607 posted

    Is there a way around this?

    The design does not sound correct for a web application but then again I cannot see the code.  Share code that reproduces this issue and the actual exception if you want or need a community code review.

    Sunday, March 29, 2020 11:28 AM
  • User297437924 posted

    I replaced the form with the timer by a form with a button, and now I require the user to click the button.   The OnClientClick event displays a GIF animation of an hourglass, and the lengthy operation is started.   

    My original goal had been that the icon on the menu would take the user to a form, and the form would automatically start saving the object, as well as display the hourglass.   This ended with an overflow message.

    As I recall the page load event had something like

    if not page.ispostback then
    timer1.interval = 100
    end if

    And then the timer1_tick event had this:

    timer1.enabled  false
    'call lengthy operation

    I think what's going is that the 'timer1.enabled=false' statement never gets a chance to stop the timer, because the lengthy operation prevents the next timer ticks from learning that they should stop.

    Sunday, March 29, 2020 6:12 PM
  • User475983607 posted

    The timer fires every 100 ms on the server.  Why?  What are you timing?   How long a process runs?   Is there anyway you can provide enough sample code the community can run to reproduce the same issue?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 29, 2020 11:39 PM
  • User288213138 posted

    Hi RateFor,

    I think what's going is that the 'timer1.enabled=false' statement never gets a chance to stop the timer, because the lengthy operation prevents the next timer ticks from learning that they should stop.

    According to your description, I cannot reproduce your problem.

    But here a demo for you as a reference about how to use the timer control.

    <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>         
                         <asp:Timer ID="Timer1" runat="server" OnTick="GetTime" Interval="100" />                              
                    </ContentTemplate>
                </asp:UpdatePanel>
    
    Protected Sub GetTime(ByVal sender As Object, ByVal e As EventArgs)
        Label1.Text = DateTime.Now.ToString("hh:mm:ss tt")
    End Sub

    If you can't solve the problem, please share your code with us.

    Best regards,

    Sam

    Monday, March 30, 2020 3:27 AM
  • User297437924 posted

    I'm not timing anything.   I'm just want the timer to fire once and only once.   '100ms' is just an arbitrary number.   The page will not display if I do the lengthy operation in the page load event, - it will be invisible until that event is over.   Thats why I have the timer - so that the page-load event will be completed, the page will display (with an animated hourglass) and then the lengthy operation will commence.   When the lengthy operation is over, it redirects to a 'finished' page.

    Wednesday, April 1, 2020 4:08 PM
  • User297437924 posted

    I probably should forget about a timer, and start a thread.

    Wednesday, April 1, 2020 4:37 PM