473,324 Members | 2,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Threaded form controlling

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?
Nov 16 '05 #1
4 1104
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
Nov 16 '05 #2
Hi,
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?

while(true){
if(STATE_FORMCLICK){
//do some work
}
if(STATE_RECBUTTONCLICK){
//do some work
}
}
Wht is wrong?

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... 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>


And, if he doesn't have anything to wait for, he could use a timer instead
of looping like that.

Cheers,
---
Tom Tempelaere
Nov 16 '05 #3
please give an example
Nov 16 '05 #4
BveB <bb****@st.cs.deu.edu.tr> wrote:
please give an example


I don't have one to hand, but read any tutorial on AutoResetEvent or
ManualResetEvent or Monitor.Wait/Pulse and you should find what you're
after.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dave McIver | last post by:
Hello all, Any help on this issue appreciated because I am getting a bit stuck! I am using VS.NET 2003. I have wrapped a multithreaded win32 dll using managed C++ and added a C# interface,...
6
by: ben | last post by:
I am needing a web service to be single threaded. Is this possible? Any ideas would be helpful
3
by: | last post by:
Hi to everybody, I have the following situation: I have a lengthy operation inside a desktop application - something that has to be executed on the main thread of the app (this is a must) .......
0
by: JeffJones176 | last post by:
Hello All: I am very new to multi-threaded programming and have a need (I think) to write an application that uses multi-threaded pages. My scenario follows: My business has multiple...
0
by: DonnaDarko | last post by:
Hi again, I have a question regarding how to control one form's values from another form. I have figured out that the best spot for this control comes from the OKButton on a form called...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.