0

I am not really sure if my title is correct since I dont really know what im doing.

I'm creating a form in Visual studio which communicates with an arduino through serialPort.

In the form I have about 9 textboxes which need to be updated / have text appended to them.

When I do that I get the "Cross thread operaton not valid" exception. After looking at stackoverflow I found a solution which is this: [Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on][1]

[1]: Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on

This solution works fine for me but its a bit awkward. since I have 9 textboxes ,I had to create 9 "SetText" methods which is quite clunky. I was wondering if there is a more general solution which I can use on every textbox I have?

Thanks in advance

Community
  • 1
  • 1
Disorbia
  • 11
  • 2

1 Answers1

0

If I understand you, maybe you could consider a more simply way. A quick solucion could be using Shared Events. Maybe you can raise a custom event from your class, and then, you only have to heard it from your Form, in order to receive the text or a more complex parameter, such a a Structure or a Class with more info (name of the control to be updated + text, or whatever you need).

Morcilla de Arroz
  • 2,104
  • 22
  • 29