Click here to Skip to main content
16,018,458 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used a timer in my webapp and it is working fine with the functionality. But my problem is the timer is getting reset-ted automatically when I it is deployed in the server. Ex: If the time is set to 70 mins, At some point it like 45min - 40min time gap it is getting reset-ted. Here is the code which I have used for this.

C#
if (Convert.ToInt32(Session["minute"]) == 0 && Convert.ToInt32(Session["seconds"]) == 0)
        {
            // Your code 
        }
        else
        {
            if (Convert.ToInt32(Session["seconds"]) < 1)
            {
                Session["seconds"] = 59;
                if (Convert.ToInt32(Session["minute"]) != 0)
                    Session["minute"] = Convert.ToInt32(Session["minute"]) - 1;
            }
            else
                Session["seconds"] = Convert.ToInt32(Session["seconds"]) - 1;
            string mins = "", sec = "";
            if (Convert.ToInt32(Session["minute"]) <= 9)
                mins = "0" + Session["minute"].ToString();
            else
                mins = Session["minute"].ToString();
            if (Convert.ToInt32(Session["seconds"]) <= 9)
                sec = "0" + Session["seconds"].ToString();
            else
                sec = Session["seconds"].ToString();
            lblTimer.Text = "Time Left : " + mins + " : " + sec;
        }
Posted

The problem is likely to be Session related - they expire after a period of time, which is normally around 20 minutes. At which point your timer will likely be destroyed. You need to look at extending your session - but not too far, they use server resources - to show your timers to work.
 
Share this answer
 
Comments
Nuthan Gowda 29-Aug-13 2:13am    
This can be done by ViewState also. The Process will be the same if i do it in ViewState ?
度娘知道你这个问题是什么或者查看下微软的帮助文档度娘知道你这个问题是什么或者查看下微软的帮助文档度娘知道你这个问题是什么或者查看下微软的帮助文档度娘知道你这个问题是什么或者查看下微软的帮助文档度娘知道你这个问题是什么或者查看下微软的帮助文档度娘知道你这个问题是什么或者查看下微软的帮助文档度娘知道你这个问题是什么或者查看下微软的帮助文档度娘知道你这个问题是什么或者查看下微软的帮助文档度娘知道你这个问题是什么或者查看下微软的帮助文档。
 
Share this answer
 
Comments
Nuthan Gowda 29-Aug-13 2:12am    
What is this ?

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