错误:跨线程操作无效:控制'listView1'从其创建的线程以外的线程访问。 plz help(我想​​将该条目插入数据库) [英] ERROR : Cross-thread operation not valid: Control 'listView1' accessed from a thread other than the thread it was created on. plz help(i want to insert that entry into database)

查看:68
本文介绍了错误:跨线程操作无效:控制'listView1'从其创建的线程以外的线程访问。 plz help(我想​​将该条目插入数据库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub SMSPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles comPort.DataReceived

       Dim str As String = ""
       Dim temp As String = ""

       objCon.GetConnectionString()
       If e.EventType = SerialData.Chars Then

           SMSPort.DtrEnable = True
           System.Threading.Thread.Sleep(100)
           tempp = SMSPort.ReadExisting().Replace(">", "").Trim()


If tempp.Length > 12 Then tempp = tempp.Substring(0, 12)

           If tempp <> "" Then
               objCon.GetConnectionString()
               objCon.GetConnection("Insert into tblAttended(Id,Status,Date,Time)values('" + tempp.ToString() + "','In','" + System.DateTime.Today.ToShortDateString() + "','" + DateTime.Now.ToShortTimeString() + "')")

               ListView1.Items.Add(tempp) //Error
               txtUniqueNumber.Text = tempp.Trim()
                ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent) //Error
           End If




           Control.CheckForIllegalCrossThreadCalls = False

   End Sub

推荐答案

您是否查看了文档:如何:对Windows窗体控件进行线程安全调用 [ ^ ]?
Did you check out the documentation: "How to: Make Thread-Safe Calls to Windows Forms Controls"[^]?


这篇关于错误:跨线程操作无效:控制'listView1'从其创建的线程以外的线程访问。 plz help(我想​​将该条目插入数据库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆