Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
VB
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
v2

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
 
Share this answer
 
Comments
Amit.p30 7-Dec-12 4:10am    
Thank u so mch..... but i havent idea regarding update variables.. kindly explain with demo...
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..........
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900