Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - 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 
Moblin 
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
     
    Iron Speed
     
    ADVERTISEMENT

    Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!

    Developing Long Running Tasks Using Asynchronous Programming with VB.NET 2005 - The asynchronous way of dealing with a long task


    (Page 4 of 4 )

    This is a very complicated method when you compare it with the method given in the previous section.  But it is essential for certain types of applications.

    To deal with the asynchronous method, you should be familiar with threading, eventing and delegating. If you are very new to delegating, I request you go through the “events and delegates” information on MSDN before proceeding with the code. The following is the entire code, which you can use as a template for your own long-running applications:

        Dim thExecuteTaskAsync As Thread = Nothing
        Private Sub StartExecuteTaskAsync()
            'clear existing thread
            If Not thExecuteTaskAsync Is Nothing Then
                thExecuteTaskAsync.Abort()
                thExecuteTaskAsync.Join()
                thExecuteTaskAsync = Nothing
            End If
            'start a new thread to execute the task asynchronously
            thExecuteTaskAsync = New Thread(AddressOf
    ExecuteTaskAsync)
            thExecuteTaskAsync.Start()
        End Sub

        Private Sub ExecuteTaskAsync()
            For i As Long = 1 To 100000
                'access delegate to show status on GUI
                Invoke(ShowStatus, New Object() {CType(i, String)})
            Next
        End Sub

        '================================================================
        ''DELEGATE declaration 
        Private Delegate Sub delShowStatus(ByVal i As String)
        Dim ShowStatus As New delShowStatus(AddressOf ShowMsg)
        Private Sub ShowMsg(ByVal i As String)
            Me.lblMessage.Text = i
        End Sub
        '=============================================================
        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e
    As System.Windows.Forms.FormClosingEventArgs) Handles
    Me.FormClosing
            'this is necessary if the form is trying to close, even
    before the completion of task
            If Not thExecuteTaskAsync Is Nothing Then
    thExecuteTaskAsync.Abort()
        End Sub

        Private Sub btnAsynchronous_Click(ByVal sender As
    System.Object, ByVal e As System.EventArgs) Handles
    btnAsynchronous.Click
            StartExecuteTaskAsync()
            MsgBox("Finished")
        End Sub

    In this article, I simply wanted to explain the basic topics of asynchronous programming in VB.NET 2005/2003. The sample codes given in this article may not be suitable for every application. You can neither consider it as the best in performance nor the best in programming methodologies. It is up to you to make the correct decision based on the necessities of the applications being developed.

    Even though I developed a simple application to test asynchronous programming for long-running-tasks, you can really develop highly complicated applications in an easy manner with the help of asynchronous programming and its features.  In my upcoming articles, I shall add a few more examples covering the same.

    If you are new to developing long-running-tasks in ASP.NET web applications, you can refer to another contribution of mine. 

    Any feedback, suggestions, bugs, errors, improvements etc., are highly appreciated at jag_chat@yahoo.com.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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

    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET
    - 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...

    Iron Speed




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