Imports System.Data.SqlClient Imports System.Threading Public Class FrmMultiThread Dim con As New SqlConnection Dim ad1, ad2, ad3 As SqlDataAdapter Dim ds As New DataSet Dim cmd As SqlCommand Dim dr As SqlDataReader Dim eid As Integer Dim th1 As Thread Dim th2 As New Thread(AddressOf ShowRecords) Dim th3 As New Thread(AddressOf Search) Private Sub FrmMultiThread_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load con.ConnectionString = "data source=seed;initial catalog=pankajp;user id=sa;password=sa;multipleactiveresultsets=true" con.Open() ComboBox.CheckForIllegalCrossThreadCalls = False MessageBox.Show("status of th2 = " & th2.ThreadState.ToString) MessageBox.Show("status of th3 = " & th3.ThreadState.ToString) th1 = New Thread(AddressOf FillCombo) th1.IsBackground = True th1.Start() 'FillCombo() is called as a therad End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click th2.Start() 'ShowRecords() is called as a therad End Sub Public Sub ShowRecords() 'represented as th3 MessageBox.Show("status of th1 = " & th1.ThreadState.ToString) MessageBox.Show("status of th2 = " & th2.ThreadState.ToString) MessageBox.Show("status of th3 = " & th3.ThreadState.ToString) ad1 = New SqlDataAdapter("select * from Dept", con) ad1.Fill(ds, "Department") DataGridView1.DataSource = ds DataGridView1.DataMember = "Department" End Sub Public Sub FillCombo() 'represented as th1 which is a background thread MessageBox.Show("status of th1 = " & th1.ThreadState.ToString) MessageBox.Show("status of th2 = " & th2.ThreadState.ToString) MessageBox.Show("status of th3 = " & th3.ThreadState.ToString) MessageBox.Show("the background thread for filling combobox is started") cmd = New SqlCommand("select empno from employee order by empno", con) dr = cmd.ExecuteReader(CommandBehavior.CloseConnection) While dr.Read ComboBox1.Items.Add(dr(0)) Thread.Sleep(3000) '3 seconds 'this thread is haulted its execution for 3000 mili seconds End While dr.Close() MessageBox.Show("the background thread is over! plz check the combobox now!!") Button2.Enabled = True End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click th3.Start() End Sub Public Sub Search() 'represented as th1 MessageBox.Show("status of th1 = " & th1.ThreadState.ToString) MessageBox.Show("status of th2 = " & th2.ThreadState.ToString) MessageBox.Show("status of th3 = " & th3.ThreadState.ToString) Dim qry As String qry = "select * from employee where empno=" & eid ad2 = New SqlDataAdapter(qry, con) ad2.Fill(ds, "employee") DataGridView2.DataSource = ds DataGridView2.DataMember = "employee" End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged eid = ComboBox1.SelectedItem End Sub End Class