- <asp:ScriptManager ID="ScriptManager1" runat="server">
- </asp:ScriptManager>
- <asp:UpdatePanel ID="UpdatePanel1" runat="server">
- <ContentTemplate>
- <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
- </asp:Timer>
- <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
- </ContentTemplate>
- </asp:UpdatePanel>
- protected void Page_Load(object sender, EventArgs e)
- {
- if (Session["CountdownTimer"] == null)
- {
- Session["CountdownTimer"] = new CountDownTimer(TimeSpan.Parse("00:02:55"));
- (Session["CountdownTimer"] as CountDownTimer).Start();
- }
- }
- protected void Timer1_Tick(object sender, EventArgs e)
- {
- if (Session["CountdownTimer"] != null)
- {
- Label1.Text = (Session["CountdownTimer"] as CountDownTimer).TimeLeft.ToString();
- string GetTime = Label1.Text;
- string[] Array = GetTime.Split(':');
- string Minutes = Array[1];
- string Seconds = Array[2];
- if (Convert.ToInt32(Minutes) == 00 && Convert.ToInt32(Seconds) == 30)
- {
-
-
- }
- else if (Convert.ToInt32(Minutes) == 0 && Convert.ToInt32(Seconds) == 0)
- {
- Session["CountdownTimer"] = new CountDownTimer(TimeSpan.Parse("00:02:55"));
- (Session["CountdownTimer"] as CountDownTimer).Start();
-
-
- }
- }
- }
- public class CountDownTimer
- {
- public TimeSpan TimeLeft;
- System.Threading.Thread thread;
- public CountDownTimer(TimeSpan original)
- {
- this.TimeLeft = original;
- }
- public void Start()
- {
-
- thread = new System.Threading.Thread(() =>
- {
- while (true)
- {
- System.Threading.Thread.Sleep(1000);
- TimeLeft = TimeLeft.Subtract(TimeSpan.Parse("00:00:01"));
- }
- });
- thread.Start();
- }
- }
I am using this code but it is not working according to my requirement.
My Requirement the countdown timer for eg:- Timer is open 10 devices and 20 devices(mobile and laptop from differenr I.P.). the timer is same all the time. run only 2 minute 55 second (5 second pause) is it possible so please help me (ASP.NET C#)