Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I developed a program that read output from a arduino uno analog pin through lan(shield). Now my problem is the text box that shows the output is only updating when i press the button. is There any way to update the text box to get the output real time other than loop and timer.

Because when the loop is used we cant use another function like on or off the digital pin.


==========
the code is
===========
textbox1.text= i;


i want this to be recurred. can any one provide me the source code
Posted

1 solution

There are ways...but a timer is the best solution.

The problem is that in order to update a textbox regularly, you need to have some indication that it should be changed - and unless you can get a "change of state" event generated by the hardware that your app can handle your only options are a timer or a loop. There are ways you can make a loop do what you want, such as moving it to a different thread (which is pretty trivial) but then you have to use Invoke to move the execution back to the "normal" UI thread to actually update the textbox, because you can't access any control except from the thread it was created on! So if your signal is changing rapidly, you will still spend more time executing "update textbox" on your UI thread than you will getting the new value on your background thread, and you will be back where you started with an unresponsive UI - but with more complicated code! :laugh:

Seriously, I'd use a Timer: set to 1/10th of a second (because most people can't react faster than that) and just set the next textbox value when it is different from last time.
 
Share this answer
 
Comments
George Jonsson 21-Nov-15 6:43am    
A very informative answer.
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900