Hi peoples....
This is a pain in the ass:
Cross-thread operation not valid: Control 'TextBox1' accessed from a thread other than the thread it was created on.
I am trying to update the text in the textbox when data is recieved on the new SerialPort control.
So I added the following: -
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
-
Dim tmp As Integer
-
Dim chr As String
-
-
tmp = Me.SerialPort1.ReadChar
-
chr = System.Convert.ToChar(tmp)
-
Me.TextBox1.Text = Me.TextBox1.Text & chr
-
End Sub
-
Which yields the previous error.
So I add the things described in: How to: Make Thread-Safe Calls to Windows Forms Controls from the MSDN but I must have done something wrong: -
Delegate Sub addtotextboxPROX(ByVal [text] As String)
-
-
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
-
Dim tmp As Integer
-
Dim chr As String
-
-
tmp = Me.SerialPort1.ReadChar
-
chr = System.Convert.ToChar(tmp)
-
Me.addtotextbox(chr)
-
-
-
End Sub
-
Private Sub addtotextbox(ByVal txt As String)
-
If Me.TextBox1.InvokeRequired Then
-
Dim d As New addtotextboxPROX(AddressOf addtotextbox)
-
Me.Invoke(d, New Object() {[Text]})
-
Else
-
Me.TextBox1.Text = Me.TextBox1.Text & [Text]
-
End If
-
-
End Sub
-
And now I get the name of the form "Form1" appended to the text box!?!?!
Can somebody please explain to me how all this stuff is supposed to work coz I can't make head nor tails of it. I've never dealt with threads before in VB but clearly it's running the code for the SerialPort control in another thread.
Please please please help
Rave-n
1 1891
OK - the following lines were wrong: - Me.Invoke(d, New Object() {[Text]})
-
Else
-
Me.TextBox1.Text = Me.TextBox1.Text & [Text]
Should have read: - Me.Invoke(d, New Object() {txt})
-
Else
-
Me.TextBox1.Text = Me.TextBox1.Text & txt
Just looking at things from the wrong point of view. It works now, but it would still be nice if someone could explain it to me :S
Cheers,
Rave-n
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Web Science |
last post by:
Site and Features: http://www.eigensearch.com
Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
|
by: * ProteanThread * |
last post by:
but depends upon the clique:
...
|
by: rollasoc |
last post by:
Hi,
Doing a bit of system testing on a Windows 98 laptop. (.Net 1.1 app).
Did a bit of testing. Loaded a previously saved file. A gray box
appeared with the text and buttons all white...
|
by: Web Science |
last post by:
Site and Features: http://www.eigensearch.com
Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
|
by: David Peach |
last post by:
Hello, hope somebody here can help me... I have a query that lists
defects recorded in a user defined date range. That query is then used
as the source for a Cross Tab query that cross-tabs count...
|
by: Web Science |
last post by:
Site and Features: http://www.eigensearch.com
Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
|
by: Rob Woodworth |
last post by:
Hi,
I'm having serious problems getting my report to work. I need to
generate a timesheet report which will contain info for one employee between
certain dates (one week's worth of dates). I...
|
by: Simon |
last post by:
Hi All,
An experiment i'm doing requires requires a synchronous cross-domain
request, without using a proxy. I wondered if anyone had any ideas to
help me achieve this.
Below is what I have...
|
by: Bart Van der Donck |
last post by:
Hello,
I'm presenting my new library 'AJAX Cross Domain' - a javascript
extension that allows to perform cross-domain AJAX requests.
http://www.ajax-cross-domain.com/
Any comments or...
|
by: ampo |
last post by:
Hello.
Can anyone help with cross-domain problem?
I have HTML page from server1 that send xmlHTTPRequest to server2.
How can I do it?
Thanks.
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |