Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - Executing Long-Running Tasks with the Prog...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Executing Long-Running Tasks with the Progress Bar in ASP.NET
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 41
    2005-08-31

    Table of Contents:
  • Executing Long-Running Tasks with the Progress Bar in ASP.NET
  • The structure of the VS.NET solution
  • The long-running process (or task)
  • Showing the progress
  • What is “ProcessingStatus.vb” in detail?

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Executing Long-Running Tasks with the Progress Bar in ASP.NET - The structure of the VS.NET solution


    (Page 2 of 5 )

    The entire VS.NET solution can be freely downloaded from this site to reuse the code in your applications. 

    Now, what does my VS.NET solution contain?  It simply contains three web forms and one class file as follows:

    • StartPage.aspx (web form)
    • UnderProcess.aspx (web form)
    • Finished.aspx (web form)
    • ProcessingStatus.vb (Class file)

    “StartPage.aspx” contains only a button to start a dummy long running process.  The control gets transferred to “UnderProcess.aspx” after the process starts. The “UnderProcess.aspx” shows the progress of achievement in the form of “Percentage complete.”  Once the process completes, the control is transferred to “Finished.aspx”, which simply shows the message “Completed Successfully” using a label.

    Even though I did not mention “ProcessingStatus.vb” in the above paragraph, it works behind the scenes.  It gets involved with both “StartPage.aspx” and “UnderProcess.aspx.”  We create a separate thread (for our process) in the “StartPage.aspx” and store information (or status) about the thread using “ProcessingStatus.vb.”  This “ProcessingStatus.vb” supplies the information to “UnderProcess.aspx” (whenever requested).

    As we start a separate thread at the server, it remains in memory and continuously works with our process (long running task) without having any relationship with “StartPage.aspx” any more.  We update the status of thread using “ProcessingStatus.vb” at every milestone of achievement.  “UnderProcess.aspx” always gets the information (or status) of the thread from “ProcessingStatus.vb” and displays it visually. Once it receives the information about the completion of thread (indirectly the process), it immediately jumps to “Finished.aspx.”

    Starting the Thread

    As explained in the previous section, “StartPage.aspx” starts a new thread for a long running process (a dummy task in this scenario).  The first important issue is that we need to import “System.Threading” to “StartPage.aspx” because we deal with threads.

    I need to provide a unique id for the process, which is going to start within the thread’s context.  It should be globally unique, because of the potential issues caused by simultaneous access to the same page by more than one user.  I declare and initialize a variable (or object) to hold a globally unique id as follows:

    ' declaring the Guid
    Dim RequestId As Guid
    ' Create a new request id
    RequestId = Guid.NewGuid()

    The next step is that we need to start a new thread as follows:

    ' Create and start a worker thread, to process "something"
    Dim ts As New ThreadStart (AddressOf doProcess)
    Dim ProcessingThread As New Thread(ts)
    ProcessingThread.Start()

    What is the funny “doProcess” in the first statement above? It is nothing but our sub-program, which starts our long running process! I separated my entire long process to be under a single sub-program for my convenience (just to attach to the thread). 

    Response.Redirect("UnderProcess.aspx?RequestId=" + RequestId.ToString())

    The above statement redirects to “UnderProcess.aspx” by carrying the globally unique id we created above.  This statement gets executed immediately after the “ProcessingThread.Start()” statement.

    The beauty of the thread is that it would never stop (or interrupt) the flow of the execution of the program, even if it doesn’t complete the process.  It hangs on in memory to complete the process independently by itself, without disturbing the flow of the execution. 

    All of the above happens when the user simply clicks on the button provided in “StartPage.aspx.”

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Thanx a lot for this. I've always thought that multithreading is only useful for...
       · Hello,The article is just only to give you an idea of implementing the progress...
       · You can still further discuss, if you have doubts. I am here to answer you.
       · Any thoughts on how this might be applied to file uploads? It seems like the...
       · You might use the concept of "streaming the binary content" for your requirement. I...
       · Hi, Thanks for sharing this code. My question is how is the 'requestId' got removed...
       · Good catch! Even I never thought of it. Right now, I could not think of very good...
       · I copied and run the code in my machine and getting "ProcessingStatus not defined"...
       · Have you had any further thoughts on "how is the 'requestId' got removed in case...
       · Hi thereI'm trying to use your example but the doprocess is not starting and...
       · Hi,I'm also using your technique to show progress, however i'm concerned about...
     

    VISUAL BASIC.NET ARTICLES

    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET (F...
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway