views:

265

answers:

1

Hi guys,

I asked a several time but must ask again, beacuse I don't know what to do: On my Page I have an auctioneer system.

Every second I must:

  • Get Information if any bidder bid on it -> Database Query
  • Countdown the timer minus 1 second
  • Update a few panel with information if there is a new bidder (history that is shown, bla)

My (funny) problem is, that only a simple ASP.Net Ajax timer (which I must have I think because I need the DAL and so on) in an Updatepanel with only the Label-Timer and a countdown of that need more then 1 single second...

That mean, when I run the timer, which only Converts the Label to DateTime, remove 1 second and update the label, in 10 normal seconds it not run 10 times, only 8 times.

So in 10 Seconds I lose 2 seconds...

I don't want to image when I begin to query the database within....

What to do?


I found out that it isn't the Performence that is too slow. The timer does'nt start every second.

I filled a Debug.Writeline with Millisecond start and end of the timer tick, here are 3 examples:

  • 2009.11.18 13:13:21:1821
  • 2009.11.18 13:13:21:1821
  • 2009.11.18 13:13:22:7021
  • 2009.11.18 13:13:22:7021
  • 2009.11.18 13:13:24:2421
  • 2009.11.18 13:13:24:2421

So it end within milliseconds, but it start again not at the right intervall (1000 milliseconds should it be!)


As wished the code:

      protected void Timer1_Tick(object sender, EventArgs e)
    {
        System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss:ffff"));
        DateTime dt = DateTime.Parse(lblTimer.Text);
        dt = dt.AddSeconds(-1.0);
        lblTimer.Text = dt.ToString("HH:mm:ss");
        System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss:ffff"));
    }

2)

                            <asp:UpdatePanel ID="up1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
    <asp:Timer ID="timeAD" Interval="1000" Enabled="true" runat="server" ontick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="lblTimer" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
+1  A: 

I know the answer now: The timer is in the Update-Panel, so the 300 milliseconds go-throug-time will be added, because the timer is restartet every imaginery postback.

Put the timer out of the update-panel and get a trigger in the panel -> Win. The timer ticks every 1 second.

Kovu