If this is your first visit, be sure to
check out the
FAQ
by clicking the
link above. You may have to
register
or
Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.
i have a thread in my program that always run as long as the program runs ( runs all the time in loop ).
i operate the Thread by the command AfxBeginThread().
i checked the cpu usage of the thead in the task manager, and i saw that the thread takes 100% cpu usage , is that OK? how can i make the CPU usage lower ? ( i tried to switch the priority parameter of the AFXBeginThread function but it doesn't change the CPU usage).

the loop is inside the thread , the AfxBeginThread is being called only once.
i use the one with the function pointer not the Runtime class.
i believe it is wrong for the cpu to behave like that ,is it ?
It is normal that the "while( true )" code to take your CPU to 100%. That is not an empty code. Your CPU does make alot or comparisons ( ( true == true ) ? ) and it makes them very fast.
You may try to add some Sleep(500) in your loop. That will give to your CPU some rest (in case you don't want your code can wait sometimes).
thanks mr.speed
, but the empty while loop is only for the example . in my program i have lots and lots of comparisons and lot of work inside the while loop and still i get 100% usage.
Thanks gstercken,
Now i understand it better, i had a felling it doesn't take all CPU usage , since i can work with other MS programs (Word,excel,etc. ) while my program runs.
is there a way to see the cpu usage of the entier computer , so i can see the cpu usage that my program takes ?
as i said before , the tight loop is only for example to check the code with/without the loop . originally , there is alot of work inside the thread.
gstercken ,
if the computer is only showing the time slices it gets assigned by the task scheduler slices , why doesn't he show other programs time slices that run at the same time ? , why only my program time slices ?
as i said before , the tight loop is only for example to check the code with/without the loop . originally , there is alot of work inside the thread.
Okay, but you also said before that the while loop is running continuously throughout the whole time that your program runs. Unless you provide some means of producing idle time (i.e. relinquishing your grip on the processor from time to time) you will end up having a tight loop, which is why you're seeing the problem that you're seeing. It doesn't matter whether the loop is doing a lot of work or only a little work. If it does a lot of work it will just loop more slowly but it will still be looping continuously.
*
The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.
*
Porting from Android to Windows 8: The Real Story
Do you have an Android application? How hard would it really be to port to Windows 8?
*
Guide to Porting Android Applications to Windows 8
If you've already built for Android, learn what do you really need to know to port your application to Windows Phone 8.
*
HTML5 Development Center
Our portal for articles, videos, and news on HTML5, CSS3, and JavaScript
*
Windows App Gallery
See the Windows 8.x apps we've spotlighted or submit your own app to the gallery!
Advertiser Disclosure:
Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.