Wednesday, March 28, 2012

Multiple Timers - Only on is ticking

Hi,

I have several UpdatePanels and a timer in each of them, as every panel has to be updated at different intervals. However, using the ASP.NET AJAX timer, only one is triggered and it seems to reset the other timers on the postback and thus the others never trigger. I was testing the Telerik Timer control and all of them were ticking properly, however it looks like they caused a memory leak in the WebDevServer as when using them, memory consumption always quickly shot up to over 1 GB.

Does anyone know of a fix or workaround how to get all timers ticking properly?

Thanks

Hi Daikoku,

as discussed inhttp://forums.asp.net/thread/1648410.aspx, the Ajax timers get reset on postback (even if they are in different update panels). I think they have only begun delving into the potential of these controls. I do not know that there is anything you can do about this behavior at this time.


Hi,

as soon as you put the Timers into the UpdatePanels, they will be reset after a partial postback.

Have you tried putting the Timers outside the UpdatePanels and referencing them as AsyncPostBack triggers?


When I place the timers outside the UpdatePanel, the whole page is reloaded on every tick

Hi,

if the timers are placed outside the UpdatePanel, you should add them as AsyncPostBack triggers for the UpdatePanel.


Thanks, that seems to work

Here is a solution I was able to use. Perhaps this will help someone visualize it. I have two timers counting off; 1 counts seconds, the other counts 60 seconds. each triggers an update panel which adds a number to a labels current integer value and re-enabled the calling trigger.

// codebehindprotected 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();if (Time1 >= 120)// stop the timer after two minutes ((Timer)sender).Enabled =false;else ((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; }
 <div> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> Seconds: <asp:Label ID="Label1" runat="server" Style=""></asp:Label> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" /> </Triggers> </asp:UpdatePanel> <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"> <ContentTemplate> Minutes: <asp:Label ID="Label2" runat="server" Style=""></asp:Label>  </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer2" /> </Triggers> </asp:UpdatePanel> </div> <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"> </asp:Timer> <asp:Timer ID="Timer2" runat="server" OnTick="Timer2_Tick"> </asp:Timer>

No comments:

Post a Comment