Hi Amit,
Here i have created sample for your reference. Refer the below code.
HTML
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer runat="server" ID="Timer1" Interval="1000" Enabled="false" OnTick="Timer1_Tick" />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<br />
<br />
<asp:Label ID="lable1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
Code
C#
protected static string content;
protected static bool inProcess = false;
protected static bool processComplete = false;
protected static string processCompleteMsg = "Finished Processing.";
protected void Page_Load(object sender, EventArgs e) { }
protected void Button1_Click(object sender, EventArgs e)
{
processComplete = false;
Button1.Enabled = false;
Timer1.Enabled = true;
Thread workerThread = new Thread(new ThreadStart(ProcessRecords));
workerThread.Start();
}
protected void ProcessRecords()
{
inProcess = true;
int x = 10; // Loop start value.
for (int i = x; i > 0; i--)
{
Thread.Sleep(1000); // Thread sleep time.
content = (i * 75).ToString(); // Multiplication of 75.
}
processComplete = true;
content = processCompleteMsg;
}
protected void Timer1_Tick(object sender, EventArgs e)
{
if (inProcess)
{
lable1.Text = content;
}
int msgLen = processCompleteMsg.Length;
if (processComplete && lable1.Text.Substring(lable1.Text.Length - processCompleteMsg.Length) == processCompleteMsg)
{
inProcess = false;
Timer1.Enabled = false;
Button1.Enabled = true;
}
}
VB.Net
Protected Shared content As String
Protected Shared inProcess As Boolean = False
Protected Shared processComplete As Boolean = False
Protected Shared processCompleteMsg As String = "Finished Processing."
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs)
processComplete = False
Button1.Enabled = False
Timer1.Enabled = True
Dim workerThread As New Thread(New ThreadStart(AddressOf ProcessRecords))
workerThread.Start()
End Sub
Protected Sub ProcessRecords()
inProcess = True
Dim x As Integer = 10
' Loop start value.
For i As Integer = x To 1 Step -1
Thread.Sleep(1000)
' Thread sleep time.
' Multiplication of 75.
content = (i * 75).ToString()
Next
processComplete = True
content = processCompleteMsg
End Sub
Protected Sub Timer1_Tick(sender As Object, e As EventArgs)
If inProcess Then
lable1.Text = content
End If
Dim msgLen As Integer = processCompleteMsg.Length
If processComplete AndAlso lable1.Text.Substring(lable1.Text.Length - processCompleteMsg.Length) = processCompleteMsg Then
inProcess = False
Timer1.Enabled = False
Button1.Enabled = True
End If
End Sub
Screenshot