Click here to Skip to main content
12,885,268 members (43,319 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
 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 = ""
        If e.EventType = SerialData.Chars Then
            SMSPort.DtrEnable = True
            tempp = SMSPort.ReadExisting().Replace(">", "").Trim()
 If tempp.Length > 12 Then tempp = tempp.Substring(0, 12)
            If tempp <> "" Then
                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
Posted 6-Dec-12 21:08pm
Updated 6-Dec-12 22:24pm
Richard MacCutchan 7-Dec-12 4:59am
You cannot access UI items in the non-UI thread. You need to save the item from the ListView in the UI thread and signal the other thread to pick it up from the saved location, and vice versa.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Did you check out the documentation: "How to: Make Thread-Safe Calls to Windows Forms Controls"[^]?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100