Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Background worker 1

Status
Not open for further replies.

mSolver

IS-IT--Management
Joined
Sep 24, 2009
Messages
16
Location
US
Hi all, my skills are novice at best when it comes to VB, so hope someone can lead me in the right direction.

Within a simple app, I have a process which returns results for a few select statements on a SQL DB and then runs a procedure. For each step I am attempting to update a listview control to show the steps to the user. Everything works great except all of the steps only display after the entire routine is completed.

I am thinking that I need to run two processes via the background worker but I am looking for feedback on the best practices to achieve this goal.

Not sure if you need my current code to make a reasonable assessment but here is a tidbit. This example will show how i am updating the listview during a sequence of events.
-----------

Main.lbStatusList.Items.Add("Processing")
Main.lbStatusList.Items(2).SubItems.Add("? Calculating source version transactions")

' SQL check for existing trans
Dim sqltransCount = New SqlCommand("Select ISNULL(count(sotrid),0) as [result] from sotr where trtpId = " & Main.cmbFromTT.SelectedValue("trtpId"), conn)
Dim sqltransDR As SqlDataReader
sqltransDR = sqltransCount.ExecuteReader
While sqltransDR.Read
Main.lbStatusList.Items(2).Text = "Completed"
Main.lbStatusList.Items(2).StateImageIndex = 1

Main.lbStatusList.Items.Add("Completed")
Main.lbStatusList.Items(3).SubItems.Add("? " & sqltransDR("result") & " transactions found in source version")
Main.lbStatusList.Items(3).StateImageIndex = 1
End While
--------------

Do I need a seperate process to run the SQL or is there a method to write to the listview control. I don't quite understand why the current code does not work.

Thanks in advance,
Mike
 
You can try a 'Me.Refresh' or a 'System.Windows.Forms.Application.DoEvents()' statement after the statements are sent to the listbox.

This temporarily gives control to the operating system allowing windows to completed a task, such as screen refreshing.
 
Thanks Bluejay, that is exactly what I was looking for, it did the trick.

Thx
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top