title: Load data in background mode using background worker in VB.NET
body: <p>I am using query from a SQLite database as the AutocompleteCustomSource for a ComboBox. Also, I want to load data in separate thread.  My LoadData method works fine when called directly, but it fails when it is called from the BackgroundWorker thread.  When it is called from the background thread, it throws a <strong><code>Specified cast is not valid</code></strong> exception on the <code>csearch.AutoCompleteCustomSource.Add(hh("Taj"))</code> line.  Below is my code:</p>
  
  <pre><code>Sub LoadData()
  
          Dim connetionString As String
          Dim cnn As SQLiteConnection
          connetionString = "Data Source=" + Application.StartupPath + "\Mydatabase.db;"
          cnn = New SQLiteConnection(connetionString)
          cnn.Open()
          Dim sqlComm88 As New SQLiteCommand("SELECT Taj FROM Taj_deu ", cnn)
          Dim hh As SQLiteDataReader = sqlComm88.ExecuteReader()
          While hh.Read()
              csearch.AutoCompleteCustomSource.Add(hh("Taj"))
          End While
  
      End Sub
  
  
  
  Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
  
          Call loaddata()
  
      End Sub
  
  
  
   Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
          BackgroundWorker1.RunWorkerAsync()
  
      End Sub
  </code></pre>