Constant read????

0 adrian contreras · February 18, 2015
Hey guys, I need some help. I am new to C# and I am not sure how to do something. What I need to do Is constantly read the cpu percentage and display it to a textbox, but the issue is I am using the windows form not the console so I cant use a while loop.  I think my best bet is to use an event, but iam not sure how. Can some one help Please? :)

Post a Reply


Oldest  Newest  Rating
0 Branislav Lazic · March 24, 2015
Because loop will block UI thread. Win Forms/WPF are singlethreaded UI toolkits. It means that all UI runs in one thread. If you run while loop, UI will "wait" (program will freeze) until loop ends (which is in your case, during all duration of program). Oh yeah! And now you will say: "I can simply use Thread.Sleep()! within while loop!" No you can't.
0 Eugene Botma · February 20, 2015
Try using a timer control (in the tool box, under "components"). Just drag it onto the form. You want to do your reading in the timers "tick" event. Remember to enable it.
0 mike richardson · March 24, 2015
Why cant you use a loop?
  • 1



C# is an object-oriented language designed for improving the development of web applications.