gpt4 book ai didi

mysql - 如何解决这个跨线程错误?

转载 作者:行者123 更新时间:2023-11-29 20:46:37 25 4
gpt4 key购买 nike

跨线程操作无效:从创建文本框的线程以外的线程访问控制文本框。 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com