Threading not working properly in i have used threading for quering database

My windows application went to "not responding state" when query is running for long time and any UI operation was performed. So i went for Threading concept. But when performing Database operation inside the Thread.start() method. It gives error like "windows application has stopped working"

My code:

 Dim Newthread As New Thread(AddressOf test)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    CONNECT_STRING = "Provider=IBMDADB2.DB2COPY1;Password=pwd;Persist Security Info=True;User ID="";Data Source="";dbalias="";"
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)      Handles Button5.Click
    strSQL = "query"
End Sub

Function test(ByVal strSQL As String)
    connection = New OleDbConnection(CON_STRING)
    Dim selectCMD As OleDbCommand = New OleDbCommand(strSQL, connection)
    Dim custDA As OleDbDataAdapter = New OleDbDataAdapter
    custDA.SelectCommand = selectCMD
    selectCMD.CommandTimeout = 0
    Dim custDS As DataSet = New DataSet()
    Dim chk As New DataGridViewCheckBoxColumn()
    chk.HeaderText = "Select Row"
    chk.Name = "Select row"
    DataGridView1.DataSource = custDS.Tables(0)
End Function

The error is occuring in the line 'custDA.Fill(custDS)'

Error - windows application has stopped working

Can anyone pls help me...


Instead of managing a thread yourself, look at backgroundworker.

Dim bw As New Backgroundworker

In the 'DoWork' Event handler of the backgroundworker, implement your database download functionality. In the 'RunWorkerCompleted' event handler of the backgroundworker update your UI.

Need Your Help

android spinner change the background color for specific items

java android spinner

i have a spinner , i want to change the background color for specific items. i mean if the object is named: country and if it have value section=true so the item of spinner will have background col...

JIRA plugins wont load after Virtual Machine suspension

virtual-machine jira

Currently, I've got JIRA 6.3.4 on a Windows Server 2008 virtual machine. The machine wasn't accessed over a period of time and was suspended, shutting down JIRA. After re-enabling the VM, JIRA fail...