Click here to Skip to main content
12,349,785 members (24,402 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 = ""
 
       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
Posted 6-Dec-12 21:08pm
Edited 6-Dec-12 22:24pm
v2
Comments
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
 
good
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"[^]?
  Permalink  

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.160621.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2016
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