By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,569 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,569 IT Pros & Developers. It's quick & easy.

How to limit CPU utilization in .NET app?

P: n/a
I have a Windows service that's built with .NET. The process is meant to run
in the background and not suck up too much CPU time. I set the thread
priority for the various threads in the service to Below Normal, but I'm
still getting reports that the service is making a noticable impact on
overall machine performance.

I stuck some Thread.Sleep calls in a various places in the code, but that
doesn't help much, since the service makes single API calls that are fairly
processor intesive (such as computing the checksum on a file) and can't be
broken down any further.

Is there some API (.NET or otherwise) or something that will allow me to to
say "Don't ever use more than 10% of the user's CPU time"?

Thanks
Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to limit the CPU utilization
in your windows service. If there is any misunderstanding, please feel free
to let me know.

As far as I know, there isn't such method to achieve this in .NET framework
or through Win32 API. Since CPU utilization is a caculated number by the
operating system, we can't simply tell the app that "Don't ever use more
than 10% of the user's CPU time", because the application doesn't know
anything about the utilization.

Setting the thread priority to a lower level might help. But it only makes
the thread sleep when there are other high priority threads available. If
no other threads, this thread also takes high CPU usage, if needed.

I think the only thing we can do is to make some Thread.Sleep call with
long sleep time. However, if there is a single CPU consuming API call in
the app, I don't think we can do much to avoid this.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #2

P: n/a
Thanks for the helpful reply. You did understand the issue correctly.

"Kevin Yu [MSFT]" wrote:
Hi,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to limit the CPU utilization
in your windows service. If there is any misunderstanding, please feel free
to let me know.

As far as I know, there isn't such method to achieve this in .NET framework
or through Win32 API. Since CPU utilization is a caculated number by the
operating system, we can't simply tell the app that "Don't ever use more
than 10% of the user's CPU time", because the application doesn't know
anything about the utilization.

Setting the thread priority to a lower level might help. But it only makes
the thread sleep when there are other high priority threads available. If
no other threads, this thread also takes high CPU usage, if needed.

I think the only thing we can do is to make some Thread.Sleep call with
long sleep time. However, if there is a single CPU consuming API call in
the app, I don't think we can do much to avoid this.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #3

P: n/a
You're welcome. Thanks for sharing your experience with all the people
here. If you have any questions, please feel free to post them in the
community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.