Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Im new with Threading and I have a Thread that Execute a Query "SELECT" When debuging the codes I've notice that on my DataReader it takes time to finish the Execution.

On My Button.Click event

VB
Dim LoadQuery As New Thread(AddressOf LoadToListView)
LoadQuery.IsBackground = True
LoadQuery.Start()


Ok I've change From Textbox to Listview so that 400 records will be shown

My LoadToListView Sub

VB
Using DataRead As SqlClient.qlDataReader = cmd.ExecuteReader
If InvokeRequired Then
    Me.Invoke(New DelegateSub(AddressOf LoadToListView)
Else
    If DataRead.HasRows Then
        While DataRead.Read
            ListView2.Items.Add(Trim(DataRead(0).ToString))
            ListView2.Items(ListView2.Items.Count - 1).SubItems.Add(Trim(DataRead(1).ToString))
            ListView2.Items(ListView2.Items.Count - 1).SubItems.Add(Trim(DataRead(2).ToString))
        End While
    Else
        MsgBox("No Data found", MsgBoxStyle.Exclamation, Me.Text)
        DataRead.Close()
        Exit Sub
    End If
End If
DataRead.Close()
End Using

1. It take 3-5 Mins for the DataReader to Execute the Command can anybody explain it to me?
2. The UI freeze even I've used threading, Do I need to use background worker or It's fine without it.
3. What are the factors that make the DataReader Reads fast ?
4. What makes it slow?

on my MS SQL the Query runs fine it only take 11Sec to Query 400 Records with 4 fields

Hope you can Enlighten me with Threadings
Posted
Updated 22-Jul-13 17:38pm
v4
Comments
Ron Beyer 22-Jul-13 21:07pm    
Can you post the code where you are using the threads?
Ron Beyer 22-Jul-13 21:10pm    
BTW, 11 seconds to get 400 records is incredibly slow, is that through the MS SQL Management studio?
onelopez 22-Jul-13 22:08pm    
I agree with Ron, 11 secs to return 400 records is pretty darn slow. Might want to figure out why it is so slow to begin with, perhaps adding some more additional indexes and what not... but this is besides the point.

From the code you have provided, it seems like you ever only display the last record to the user. Might want to change your sql statement to only pull one record instead of 400. This will definitely provide the speed boost you want.
Sergey Alexandrovich Kryukov 22-Jul-13 22:19pm    
And where are the threads? Do you really have more than one? :-)
—SA
iMaker.ph 22-Jul-13 23:22pm    
yes The 1st One is to Query From the Database passing the data to my Set/Get then After the 1st Thread I've Declared another thread for Passing the SET/GET to TextBox that what Am planning. Am I doing it right or just pass that data directly to the UI ?

1 solution

You cannot touch UI controls from anything other than the UI thread (startup). Your code won't even work to begin with. Your textbox update in a loop thing will do precisely nothing. It'll show you the final record in the reader and that's it.

There's no way for us to tell what's causing your SQL to execute so slowly. It's shouldn't take that long to return 400 records. My first guess would be your not indexing your database table correctly.

What exactly are you trying to do?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900