Same way You need to set the startValue and End value and based on interval and OnTick event you can decrement the value.
and onces it reach the end value you just need to stop it.
If you are using System.Timers.Timer you can stop like this
timer.Enabled = false;
If you are using System.Threading.Timer, use this
timer.Change(Timeout.Infinite , Timeout.Infinite);
If you are using System.Windows.Forms.Timer
timer.Stop();
Refer the below sample code and as per your requirement you can implement logic as per your code logic.
HTML
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<contenttemplate>
<asp:Label ID="lblTime" runat="server" />
<asp:Timer ID="Timer1" runat="server" OnTick="SetTime" Interval="1000" />
<br /><asp:Label id="lblMessage" runat="server" ></asp:Label>
</contenttemplate>
</asp:UpdatePanel>
C#
public static int StartTime = 1;
public static int EndTime = 5;
protected void SetTime(object sender, EventArgs e)
{
lblTime.Text = Convert.ToString(StartTime);
StartTime += 1;
if (StartTime > EndTime)
{
Timer1.Enabled = false;
lblMessage.Text = "Timer stop";
StartTime = 1;
}
}
VB.Net
Public Shared StartTime As Integer = 1
Public Shared EndTime As Integer = 5
Protected Sub SetTime(ByVal sender As Object, ByVal e As EventArgs)
lblTime.Text = Convert.ToString(StartTime)
StartTime += 1
If StartTime > EndTime Then
Timer1.Enabled = False
lblMessage.Text = "Timer stop"
StartTime = 1
End If
End Sub
Screenshot