Changing the value of text box at run time in .net 2.0 windows application
-
Hi, I want to change the value of text box at run time in windows application with c#.net 2005. But,I am getting the error Cross-thread operation not valid.Can anybody tell what is the reason
It appears that the code that's trying to alter the textBox is running on a seperate thread. What object is trying to alter it?
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Expect everything to be hard and then enjoy the things that come easy. (code-frog) -
It appears that the code that's trying to alter the textBox is running on a seperate thread. What object is trying to alter it?
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Expect everything to be hard and then enjoy the things that come easy. (code-frog) -
Hi, I want to change the value of text box at run time in windows application with c#.net 2005. But,I am getting the error Cross-thread operation not valid.Can anybody tell what is the reason
This article can help you: Beginners Guide To Threading In .NET Part 5 of n[^]
Giorgi Dalakishvili #region signature my articles #endregion
-
I just want to enter the value at runtime which is coming from the serial port donot have any idea about any other object
show these portions of your code 1. how you create your serial port reader 2. where you get the text from the serial port and attempt to assign to the textbox's Text property.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Expect everything to be hard and then enjoy the things that come easy. (code-frog) -
show these portions of your code 1. how you create your serial port reader 2. where you get the text from the serial port and attempt to assign to the textbox's Text property.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Expect everything to be hard and then enjoy the things that come easy. (code-frog) -
Serial Port Declaration : private SerialPort comport = new SerialPort(); reponse from com port : string response = comport.ReadExisting() Changing the value : textbox1.text = response.Substring(0, 1)
There's nothing using threading in the code you've posted. I assume you're using a thread to read the port, is your serial port declaration in there? BTW, there's a simple example on MSDN[^] - it might be worth comparing to your code.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Expect everything to be hard and then enjoy the things that come easy. (code-frog) -
I just want to enter the value at runtime which is coming from the serial port donot have any idea about any other object
I guess you're setting the text from within the comport_DataReceived event handler, which the SerialProt object calls from another thread. Either you read up on threading, or you don't use the event but put a timer onto your form (or control) and poll the com port from the timer's Tick event.
-
I guess you're setting the text from within the comport_DataReceived event handler, which the SerialProt object calls from another thread. Either you read up on threading, or you don't use the event but put a timer onto your form (or control) and poll the com port from the timer's Tick event.