How to Programmatically Limit Bandwidth Usage of My C# Application

How to programmatically limit bandwidth usage of my c# application?

What you are looking for is called Bandwidth throttling And here is a good example how is this done, also review the comments to know how it is done from a client side.

You may also want to take a look at this example too, putting things in a real application

Can i write a program to limit the Internet usage to 40mb per day?

  1. You need to monitor the network activity. One can use IPGlobalProperties class for that.

    Keep in mind that the statistics are reseted each time the connection is lost so you'll have to store them somewhere.

  2. You need to disable internet connection, see Code to enable/disable internet connectivity

Limit Bandwidth Speeds

Take a look at http://www.codeproject.com/KB/IP/MyDownloader.aspx

He's using the well known technique which can be found in Downloader.Extension\SpeedLimit

Basically, before more data is read of a stream, a check is performed on how much data has actually been read since the previous iteration . If that rate exceeds the max rate, then the read command is suspended for a very short time and the check is repeated. Most applications use this technique.

How can I programmatically limit my program's CPU usage to below 70%?

That's not your concern... It's the job of the operating system to distribute processor time between running processes. If you'd like to give other processes first crack at getting their stuff done, then simply reduce the priority of your own process by modifying the Process.PriorityClass value for it.

See also: Windows Equivalent of ‘nice’



Related Topics



Leave a reply



Submit