Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Haii..

My problem is i using timer in my asp.net online exam website .
one user login to attempt test my timer reducing time value work as fine but multiple users attempted to the test that time my timer has skipping the ticks and its goes very fast ..i don't know what is the reason please help me..

advance thanks to you ...
My code.cs is

What I have tried:

protected void timer1_tick(object sender, EventArgs e)
        {
            
            if (TimeAllSecondes > 0)
            {
                TimeAllSecondes = TimeAllSecondes - 1;
                if (TimeAllSecondes < 0)
                {
                    Session["endtime"] = DateTime.Now;
                    //Session["SubjectID3"] = txtsubid.Value;
                    //Session["SubjectName3"] = txtsubname.Value;
                    mcqmethod.update_astatus(Convert.ToString(Session["empid"]), Convert.ToInt32(Session["EXAMID"]));
                    Response.Redirect("~/MCQ/students/s_thankyou.aspx");
                  
                }
            }

            TimeSpan time_Span = TimeSpan.FromSeconds(TimeAllSecondes);
            hh = time_Span.Hours;
            mm = time_Span.Minutes;
            ss = time_Span.Seconds;
            lblTimer.Text = " Your exam time is remaining :  " + hh + ":" + mm + ":" + ss + "[H:M:S]";
         

        }

 <asp:Timer ID="timer1" runat="server" Interval="1000" OnTick="timer1_tick" ></asp:Timer>
Posted
Updated 10-Apr-17 20:49pm

1 solution

Don't time ticks - counting them doesn't work as it's inherently inaccurate - this isn't a real time system, so timer accuracy is not guaranteed.

Instead, get the actual time (from your server) at the beginning of the exam, and add the exam duration to that. Every time you need to check if the time allowed is over, get the time from the server again, and compare it. If the new time is past the "end of exam" time, the exam is over.
Similarly, to display a "you have x minutes left" subtract the current server time from the "end of exam" time and display the remaining duration from that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900