Daily using/supporting

Get Firefox browser!
Get Thunderbird!
Get Opera browser!
Get The Gimp!
Get Inkscape!
Get LibreOffice!
Get Videolan!
Get Linux!
Get Mandriva!
Get Joomla!
Hacker Emblem

Archives

Which topics would you like us to cover more?

Latest comments

Latest tweets

about 1 day ago Using REDIPS.drag to add drag and drop to your .Net webapplication #li #dib0 http://t.co/n8zY3s7d
about 7 days ago http://t.co/cknQcDbo #Kindle
about 15 days ago Freedom isn't the ability to choose what to do or say, but the ability to choose what not to do or say #freedom
about 29 days ago http://t.co/61KTQknI #Kindle
12 Apr 2012 Force the use of a networking adapter using C# #li #dib0 http://t.co/ZTJOPzOz
9 Apr 2012 Mandriva 2010.2 and USB devices in Virtualbox http://t.co/fwq9gbHB
9 Apr 2012 Execute a http request to you own site with PHP http://t.co/DIvWPrpd
Home Architecture, security and coding .Net: Ajax, multiple timers on one page
.Net: Ajax, multiple timers on one page
Written by Division by Zero   
Saturday, 21 November 2009 12:12

A while ago I was building  web application with multiple timers on one page (in different usercontrols, which had to work independently). I thought it worked, but after some debugging I found out that only one timer event worked. After a callback the other timer started to count from the beginning. So, this is the solution I came up with (and I haven't found or thought of a better one).

private int GetCorrectedInterval()
 {
 int interval = DefaultRefreshTime;
 interval *= 1000;

 // If a page has multiple timers, the timers that didn't fire an event
 // will be reset. This will correct the interval, so this timer will fire sooner
 ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
 if (!scriptManager.AsyncPostBackSourceElementID.Contains(UpdatePanelTimerId))
 {
 // This timer didn't fire
 if (Session["LastTimerEvent"] != null)
 {
 DateTime lastFireDate = (DateTime)WebSession.ApplicationSession[SessionLastTimerEvent];
 TimeSpan diff = DateTime.Now.Subtract(lastFireDate);

 interval -= (int)diff.TotalMilliseconds;
 if (interval < 1)
 interval = 10;
 }
 else
 Session["LastTimerEvent"] = DateTime.Now;
 }
 else // This timer did fire, set the session value
 Session["LastTimerEvent"] = DateTime.Now;

 return interval;
 }
 

Add comment


Security code
Refresh

Computers are useless. They can only give you answers. - Pablo Picasso


© 2009 - 2012, Division by Zero

Template based on the empire template by joomlashack 

Valid XHTML 1.0 Strict  Valid CSS!  Creative Commons License
This work by Division by Zero is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Netherlands License.