Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have to develop multi user online exam system all work is completed but one problem is that
when another user login in exam system then his timer value change the previous user Timer value.
i have use 2 static int value for minute and second.
Please help my code is

C#
static int tmpStartmin = 0;
static int tmpStartSecond = 59;

 protected void SetExamTimer()
    {

        Timer1.Enabled = false;
        if (Session["QStartTime"] == null)
            Session.Add("QStartTime", DateTime.Now);
        else
            Session["QStartTime"] = DateTime.Now;
        SqlConnection sqcontime = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStr"].ConnectionString);
        string sqtime = "";
        DataTable dtt = new DataTable();
        sqtime = "Select Top 1 * from TimeLog Where QuestionPaper_ID=" + int.Parse(Session["QuesPaper_ID"].ToString()) + " and Registration_ID=" + int.Parse(Session["RegistrationID"].ToString()) + " and isdeleted=0 Order by Timelog_Id desc ";
        SqlDataAdapter adptime = new SqlDataAdapter(sqtime, sqcontime);
        adptime.Fill(dtt);
        if (dtt.Rows.Count > 0)
        {
            divTime.Visible = true;
            Timer1.Enabled = true;
            if (Session["QStartTime"] == null)
                Session.Add("QStartTime", DateTime.Now);
            else
                Session["QStartTime"] = DateTime.Now;
            lblTime.Text = dtt.Rows[0]["Time"].ToString();          
            tmpStartmin = Convert.ToInt32(dtt.Rows[0]["Min"].ToString());
            tmpStartSecond = Convert.ToInt32(dtt.Rows[0]["Sec"].ToString());
            lblMinute.Text = tmpStartmin.ToString();
            lblSeconds.Text = tmpStartSecond.ToString();

        }
        else
        {


            string sqq = "";
            DataTable dt = new DataTable();
            sqq = "Select * from StDetail Where QuestionPaper_ID=" + int.Parse(Session["QuesPaper_ID"].ToString()) + " and isdeleted=0";
            SqlDataAdapter dq = new SqlDataAdapter(sqq, System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStr"].ConnectionString);
            dq.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                divTime.Visible = true;
                Timer1.Enabled = true;
                if (Session["QStartTime"] == null)
                    Session.Add("QStartTime", DateTime.Now);
                else
                    Session["QStartTime"] = DateTime.Now;
                lblTime.Text = dt.Rows[0]["FixedExamTime"].ToString();
                tmpStartmin = Convert.ToInt32(dt.Rows[0]["FixedExamTime"].ToString()) - 1;
                lblMinute.Text = tmpStartmin.ToString();
                lblSeconds.Text = tmpStartSecond.ToString();
            }
            else
            {
                divTime.Visible = false;
                Timer1.Enabled = false;
                if (Session["QStartTime"] == null)
                    Session.Add("QStartTime", DateTime.Now);
                else
                    Session["QStartTime"] = DateTime.Now;
            }


        }
    }
Posted

You answered it for yourself - don't use static variables where instance variables are needed -
 
Share this answer
 
Comments
Rahul VB 1-Jul-14 9:38am    
Perfect. My 5!!!!
I faced the same problem before this. So i looked at this and found out the answer.
packodilal 2-Jul-14 4:34am    
dear johannesnestler,
can you modify in my code .thanks in advance
when user logged in you can reset the values as below
C#
protected void SetExamTimer()
{
  tmpStartmin=0;
  tmpStartSecond = 59;


or use another two session values for start minutes and start seconds. clear those session values on user log out and log in.
 
Share this answer
 
v2
Comments
packodilal 1-Jul-14 4:33am    
dear DamithSL,
my system is a online banking exam system in which multiples user give exam same time and some of
close exam in betwween then next time login timer is start on the basis of last log out ..so kindly read my code care fully and give solution

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