Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

How to do Asynchronous Loading of Data Without Threading.

Total Hit ( 3696)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Sometimes we need to work with long running task but still we dont want to stop responding other events in this type of situation mostly we will think about implementing threading. But here is more easy way without implementing threading.

Today we will discuss about IAsyncResult class found in System.Threading following example will show you how perform long running task Asynchronously

To implement this code create a new win application project

- Add one listbox on form1
- Add following code for form1

Click here to copy the following block
Imports System.Threading

Public Class Form1
  Inherits System.Windows.Forms.Form

  Private Delegate Sub Starter()

  Private Sub DoLongTask()
    Dim i As Integer

    ListBox1.BeginUpdate()
    For i = 1 To 200000
      ListBox1.Items.Add(i)
    Next
    ListBox1.EndUpdate()
  End Sub

  Private Sub Form1_Load(ByVal sender As Object, _
       ByVal e As System.EventArgs)
       Handles MyBase.Load
      
    Dim asy As IAsyncResult

    asy = BeginInvoke(New Starter(AddressOf DoLongTask))
  End Sub
End Class

Another important thing to note about this example is we have used BeginUpdate and EndUpdate method which will give you extra performance. When you use BeginUpdate and EndUpdate methods of ListBox then .net framework will not update listbox until you call EndUpdate. Its a batch update instead of single item update so for 200000 items it will update only once.


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.