Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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()
 
// here i want to add th split charcters
        '   For i As Integer = 1 To tempp.Length Step 12
            '  Debug.Write(Mid(tempp, i, 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)  '<big>ERRORR</big>
                txtUniqueNumber.Text = tempp.Trim() ''<big>ERRORR</big>
                ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
            End If
            'Next i
            Control.CheckForIllegalCrossThreadCalls = False
End Sub
Posted 6-Dec-12 20:08pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

HI,
You must be calling this method from delegate which send it to different thread and from different thread you cannot access the primary thread. what you should do is just update variables and access them from Primary thread.
 
I guess it may help you.
 
RKS
  Permalink  
Comments
Amit.p30 at 7-Dec-12 4:10am
   
Thank u so mch..... but i havent idea regarding update variables.. kindly explain with demo...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hello! Amit,
 
First, You have to declare one variable for every property your want to change at application level. so that u can access these variables in your primary thread as well as secondary thread.
 
Now, instead of updating the property directly, you have to update the property from secondary thread and access that variable in primary thread to update the desired property.
 

hope it helps,
 
mark as answer if helped..........
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,805
1 OriginalGriff 6,696
2 CPallini 5,350
3 George Jonsson 3,609
4 Gihan Liyanage 2,792


Advertise | Privacy | Mobile
Web03 | 2.8.140922.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2014
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