vb.net threading

Gast #4943484
Lesenswert?

hallo,
habe diesen code zur Auswertung einer Fernbedienung:
1
    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
2
        ReceivedText(SerialPort1.ReadExisting())    'Automatically called every time a data is received at the serialPort
3
    End Sub
4
    Private Sub ReceivedText(ByVal [text] As String)
5
        'compares the ID of the creating Thread to the ID of the calling Thread
6
        If Me.rtbReceived.InvokeRequired Then
7
            Dim x As New SetTextCallback(AddressOf ReceivedText)
8
            Me.Invoke(x, New Object() {(text)})
9

10
        Else
11
            Me.rtbReceived.Text &= [text]
12
        End If
13

14
        If Strings.Left(text, 1) = "$" And Strings.Right(text, 1) = "$" Then
15
            'Beep()
16
            Dim twx_cmd As Byte
17
            twx_cmd = Mid(text, 2, 3)
18
            Select Case twx_cmd
19
                Case 25 'zif-1
20
                    If st_modus = "radio" Then
21
                        Button1_Click(Nothing, Nothing)
22
                    End If
23
                Case 49 'zif-2 
24
                    If st_modus = "radio" Then
25
                        Button2_Click(Nothing, Nothing)
26
                    End If
27
                Case 189 'zif-3 
28
                    If st_modus = "radio" Then
29
                        Button3_Click(Nothing, Nothing)
30
                    End If
31
                Case 17 'zif-4 
32
                Case 57 'zif-5
33
                Case 181 'zif-6 
34
                Case 133 'zif-7
35
                Case 165 'zif-8
36
                Case 149 'zif-9
37
                Case 27 'zif-0 
38

39

40
                Case 137 '2-1 mod
41
                    If st_modus = "radio" Then
42
                        Button11_Click(Nothing, Nothing)
43
                    End If
44
                    If st_modus = "mp3_playlist" Then
45
                        Button1_Click(Nothing, Nothing)
46
                    End If
47

48

49
            End Select
50

51
        End If
52

53

54
    End Sub

fb25/49/189 funktioniert, fb137 kommt Fehlermeldung:
Ungültiger threadübergreifender Vorgang: Der Zugriff auf das 
Steuerelement ListBox1 erfolgte von einem anderen Thread als dem Thread, 
für den es erstellt wurde.

Wieso hab ich ab hier
      'compares the ID of the creating Thread to the ID of the calling 
Thread

zwei threads und wie greife ich auf den anderen thread zu?

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren