1

I've a small web app which displays time in different time zones. Time calculation seems to be correct. I use the timer control to generate postback.

<asp:Timer ID="Timer1" runat="server" Interval="60000" OnTick="Refresh_Time">
</asp:Timer>

Question:

The problem is the page refresh is not synchronized with the server clock. For example, if I've started the app at 9.55.30 AM , the next postback is at 9.56.30 AM So, right now, I've to watch the server clock and start the app at the when it is 0 seconds. Something like 9.57.00 AM. Obviously, it is never 100% accurate.

Ideally, what I'm looking for is, no matter when I run the app 9.55.15 AM or 9.55.45 AM, the next postback should happen at 9.56.00 AM. Any help is appreciated.

EDIT

The code that solve the problem

protected void Page_Load(object sender, EventArgs e)
{        
    Timer1.Interval = 1000*(60 - DateTime.Now.Second);

}
gmail user
  • 2,753
  • 4
  • 33
  • 42

2 Answers2

0

In the page_load of your code behind you will need to calculate the actual interval to send to the client and set it there.

NotMe
  • 87,343
  • 27
  • 171
  • 245
0

Have you considered, in your Refresh_Time method, having the server do some sort of wait to post back until it reaches the minute?

Also, I quickly found an existing question on 'push' notifications in ASP.NET. That could be a good option, too, because you can't assume the client can ever know what time it is on the server.

Community
  • 1
  • 1
Adam Miller
  • 767
  • 1
  • 9
  • 22