Click here to Skip to main content
12,398,537 members (58,743 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()
// 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.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>
            End If
            'Next i
            Control.CheckForIllegalCrossThreadCalls = False
End Sub
Posted 6-Dec-12 20:08pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

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.160721.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