跨线程操作无效:从创建文本框的线程以外的线程访问控制文本框。 vb.net
Sub autocompletepayee()
Dim cmd2 As New Odbc.OdbcCommand
Dim dr As Odbc.OdbcDataReader
Dim myquery As String
myquery = "select payee from tbrequest"
cmd2.CommandText = myquery
cmd2.Connection = con
dr = cmd2.ExecuteReader
While dr.Read
txtPayee.AutoCompleteCustomSource.Add(dr.GetString(0)) 'this is the line where the error prompt
End While
dr.Close()
最佳答案
这应该可行,尽管如果更多地了解代码所在的位置,它可能会更短
Dim cmd2 As New Odbc.OdbcCommand
Dim dr As Odbc.OdbcDataReader
Dim myquery As String
myquery = "select payee from tbrequest"
cmd2.CommandText = myquery
cmd2.Connection = con
dr = cmd2.ExecuteReader
While dr.Read
If txtPayee.InvokeRequired Then
txtPayee.Invoke(Sub()
txtPayee.AutoCompleteCustomSource.Add(dr.GetString(0)) 'this is the line where the error prompt
End Sub)
Else
txtPayee.AutoCompleteCustomSource.Add(dr.GetString(0)) 'this is the line where the error prompt
End If
End While
dr.Close()
关于mysql - 如何解决这个跨线程错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38406932/