Executing Long-Running Tasks with the Progress Bar in ASP.NET - Showing the progress
(Page 4 of 5 )
This is the actual section which shows the progress to the user in the form of a progress bar. The “UnderProcess.vb” takes care of this process.
The “UnderProcess.vb” mainly contains two labels, “lblMsg” and “lblProgressBar.” “lblMsg” shows what percentage it has completed in the form of words. “lblProgressBar” was designed with a blue background color. This gets expanded (indirectly; the width of the label) based on the percentage value for every auto-refresh of the same page. The following is the entire code present in the “page load“ event of “UnderProcess.vb.”
' Get the request id
Dim requestId As New Guid(Request.
QueryString("RequestId").ToString())
'Check the processing thread status collection
If (ProcessingStatus.Contains(requestId))Then
'StatusValue contains either a value between 0 to 100 or -1 (-1 shows that the task is finished)
Dim StatusValue As Integer =
CType(ProcessingStatus.getValue(requestId), Integer)
If StatusValue = -1 Then
'processing task succesfully finished
ProcessingStatus.remove(requestId)
'remove the status
Response.Redirect("finshed.aspx")
'go to result page
EndIf
'if not finished, display the status
' Remove the status from the collection
Me.lblMsg.Text = "Wait for a moment.." & StatusValue & "% Completed.."
Me.lblProgressBar.Width = Unit.Pixel(2 * StatusValue)
'200 pixels for 100%
EndIf
' The processing has not yet finished
' Add a refresh header, to refresh the page in 2 seconds.
Response.AddHeader("Refresh", "2")
I commented the above program very clearly to help you understand every statement in detail. I hope you can understand it.
The “Finshed.aspx” has nothing other than a simple label with a message “Completed Successfully.” No processing is done at “Finished.aspx”.
Next: What is “ProcessingStatus.vb” in detail? >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee