BveB <bb****@st.cs.deu.edu.tr> wrote:
I want to make a listener thread for some actions on windows forms but
when I use Thread class cpu usage goes to 100% what can I do?
private void Th_Func(){
while(true){
if(STATE_FORMCLICK){
//do some work
}
if(STATE_RECBUTTONCLICK){
//do some work
}
}
}
Wht is wrong?
What's wrong is you're tight-looping. You should use something like
Monitor.Wait/Pulse or a Manual or AutoResetEvent so that your thread
spends most of its time waiting, instead of it polling the whole time.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too