Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - Developing Long Running Tasks Using Asynch...
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 
Actuate Whitepapers 
VeriSign Whitepapers 
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

Developing Long Running Tasks Using Asynchronous Programming with VB.NET 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 15
    2006-07-31

    Table of Contents:
  • Developing Long Running Tasks Using Asynchronous Programming with VB.NET 2005
  • What exactly is the problem?
  • The solution is here
  • The asynchronous way of dealing with a long task

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Developing Long Running Tasks Using Asynchronous Programming with VB.NET 2005 - What exactly is the problem?


    (Page 2 of 4 )

    Selecting a method for displaying/presenting the status to the user is not a problem at all. The problem always lies with the synchronization of the process and presentation. 

    Sometimes we cannot anticipate how much time the process will take to complete. In such scenarios, it is useless to select a method which shows an expected finishing time. We really need to justify the scenario and possibilities to the best of our abilities. Once the selection is made, we need to implement it with a particular approach.

    Now we come to the point of our “approach.” Most developers don’t care about the best and most professional approaches for dealing with the issues of long-running tasks. To be frank, any professional approach is a bit difficult to achieve.  But if we make it in the form of a template, it could be reused a number of times.

    Let us consider the normal approach for working with a task. I prepared a long-running task as follows:

    PrivateSub ExecuteTask()
            For i As Long = 1 To 10000000
                Me.lblMessage.Text = i
            Next
        End Sub

    To execute the above task, I wrote the following code in a button click event:

    PrivateSub btnNormal_Click(ByVal sender As System.Object, ByVal e
    As System.EventArgs) Handles btnNormal.Click
            ExecuteTask()
            MsgBox("Finished")
        End Sub

    There exists no complication anywhere in any of the above programs. I am showing the status of my task using “lblMessage.” If you execute your application, your application hangs (or doesn’t respond to you) for some time. It only responds when the application has executed the task successfully. Even if you ask it to show you the status, it will not respond in a timely fashion. 

    How do we deal with this issue professionally? Go through the next section for a solution.

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · hello guys. This contribution introduces you to work with long running tasks. enjoy...
       · I have code in which i need to enable a cancel button during a process.Right now i...
       · In Vb, you can use the same code that is called when the task starts to make sure it...
       · If you don't add "application.DoEvents" to the ExecuteTask Sub, the system will hang...
     

    VISUAL BASIC.NET ARTICLES

    - 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 ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic





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