Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Need Help With Threading Issue...

Need Help With Threading Issue...

Scheduled Pinned Locked Moved Visual Basic
helpcsharpdatabasequestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mayhem_rules
    wrote on last edited by
    #1

    Hi, I am new to .Net and working with threads for the first time. Please review the code below. Dim t As Thread t = New Thread(AddressOf Me.GetValue) ' GetValue is a procedure t.Start() In GetValue, I want to get some data from the DB and fill in a combobox. However, when the following code in GetValue executes - str = "select ID from ABC" DA = New OleDbDataAdapter(str, ipcon) DS = New DataSet DA.Fill(DS, "rec") - the control is lost. i.e: the next set of statements (to fill the combobox with the dataset values) do not execute. I am not sure why such a thing is happening. Is there some way to handle this threading issue that I am missing? Please help. With Best Regards, Mayur

    R 1 Reply Last reply
    0
    • M mayhem_rules

      Hi, I am new to .Net and working with threads for the first time. Please review the code below. Dim t As Thread t = New Thread(AddressOf Me.GetValue) ' GetValue is a procedure t.Start() In GetValue, I want to get some data from the DB and fill in a combobox. However, when the following code in GetValue executes - str = "select ID from ABC" DA = New OleDbDataAdapter(str, ipcon) DS = New DataSet DA.Fill(DS, "rec") - the control is lost. i.e: the next set of statements (to fill the combobox with the dataset values) do not execute. I am not sure why such a thing is happening. Is there some way to handle this threading issue that I am missing? Please help. With Best Regards, Mayur

      R Offline
      R Offline
      RichardBerry
      wrote on last edited by
      #2

      Try Instantiating the Datatable on the main thread before you start the second thread: Dim dt As New DataTable("dt") Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim thrFillTable As New Threading.Thread(AddressOf FillTable) thrFillTable.Start() End Sub Private Sub FillTable() Dim c1 As New DataColumn("Number") dt.Columns.Add(c1) Dim dr As DataRow For i As Integer = 0 To 10 dr = dt.NewRow dr.Item(0) = i.ToString dt.Rows.Add(dr) 'Next line is just to waste time 'so you will see combo has no data 'till thread Is finished Threading.Thread.Sleep(2000) Next Me.ComboBox1.DataSource = dt Me.ComboBox1.DisplayMember = "Number" End Sub

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups