Page view counter

Timer Control - Multiple Timers

Last post 04-03-2007 3:02 AM by bapo_10@hotmail.com. 2 replies.

Sort Posts:

  • Timer Control - Multiple Timers

    04-02-2007, 4:02 PM
    I need to use two different timed updates within two different update panels. Ajax doesnt seem to like two Ajax Timers on the same page. Does anyone know if this is correct please??
  • Re: Timer Control - Multiple Timers

    04-02-2007, 4:49 PM
    • Loading...
    • pixelsyndicate
    • Joined on 07-04-2003, 12:56 PM
    • W. MI transplant in N. TX
    • Posts 1,082
    • Points 6,012

    Hi Bapo,

    I created a small timer using two different timers in different update panels and was only able to get the Tick event for one of them... I suspect the "postback" in one of the update panels causes the second timer to reset.  I have tested this by setting one to 1 second intervals and the other to 2 second... then to reverse them.  Only the first triggered tick would trigger the events.

        protected void Page_Load(object sender, EventArgs e)
        {
    
            if (!IsPostBack)
            {
                Label1.Text = "0";
                Label2.Text = "0";
            }
    
        }
        protected void Timer1_Tick(object sender, EventArgs e)
        {
            int Time1 = Convert.ToInt16(Label1.Text);
            Time1 += 1;
            Label1.Text = Time1.ToString();
            ((Timer)sender).Enabled = true;
    
        }
        protected void Timer2_Tick(object sender, EventArgs e)
        {
            int Time2 = Convert.ToInt16(Label2.Text);
            Time2 += 1; 
            Label2.Text = Time2.ToString();
            ((Timer)sender).Enabled = true;
        }
     

     

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Label ID="Label1" runat="server" Style="position: relative"></asp:Label>
                    <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
                    </asp:Timer>
                </ContentTemplate>
            </asp:UpdatePanel>
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <asp:Label ID="Label2" runat="server" Style="position: relative"></asp:Label>
                    <asp:Timer ID="Timer2" runat="server" Interval="2000" OnTick="Timer2_Tick">
                    </asp:Timer>
                </ContentTemplate>
            </asp:UpdatePanel>
     

     

    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." ~ Douglas Adams

    http://pixelsyndicate.com/ps/
  • Re: Timer Control - Multiple Timers

    04-03-2007, 3:02 AM

    Thanks for your time.

    I've got realTime forex data and the stats used to enter trades needs to be examined on multiple time frames and so collated on min 5min, hour, day ... I can do it with one timer using conditional statements and scaling up from the minute stats but its wasting costly cycles exactly where this thing needs to perform. A one hour triggered timer & a one day triggered timer ..... seemed a sensible way to go. Unless I'm missing something having two active timers in two seperate update panels (or better the same update panel) would be of benefit?

     

    Anyhow thanks for the response

Page 1 of 1 (3 items)