问题描述
我对应用程序的需求是限制控制台应用程序中的带宽。
请根据需要提出建议。
提前致谢。
我尝试过:
到目前为止,我已经尝试了一些平均速度。我也试过Throttling Stream类,但没有找到相关内容,因为我是新手。
请建议我一些逻辑。
public static void ShowInterfaceSpeedAndQueue()
{
NetworkInterface [] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach(NetworkInterface adapter in适配器)
{
IPInterfaceProperties properties = adapter.GetIPProperties();
IPv4InterfaceStatistics stats = adapter.GetIPv4Statistics();
Console.WriteLine(adapter.Description);
Console.WriteLine(Speed ........................ .........:{0},
adapter.Speed);
Console.WriteLine(输出队列长度...... ..............:{0},
stats.OutputQueueLength);
}
秒表秒表=新秒表();
秒表。开始();
WebClient webClient = new WebClient();
string address =ftp:// speedtest:[email protected]/test10Mb.db;
var uri = new Uri(地址);
webClient.DownloadFile(uri,D:\\Sample3.db);
//Console.WriteLine(已过去的时间:{0},秒表。已经过了);
string time = Convert.ToString(stopwatch.Elapsed);
double timeInSecond = TimeSpan.Parse(time).TotalSeconds;
int speed = 10240 / Convert.ToInt32(timeInSecond);
Console.WriteLine(平均下载速度:+速度+kbps);
}
My need for the application is to limit the bandwidth in the console application.
Please suggest something according to the need.
Thanks in advance.
What I have tried:
I have tried something to get the average speed till now. I also tried Throttling Stream class, but didn't found something related as i am new to this.
Kindly suggest me some logic for that.
public static void ShowInterfaceSpeedAndQueue()
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in adapters)
{
IPInterfaceProperties properties = adapter.GetIPProperties();
IPv4InterfaceStatistics stats = adapter.GetIPv4Statistics();
Console.WriteLine(adapter.Description);
Console.WriteLine(" Speed .................................: {0}",
adapter.Speed);
Console.WriteLine(" Output queue length....................: {0}",
stats.OutputQueueLength);
}
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
WebClient webClient = new WebClient();
string address = "ftp://speedtest:[email protected]/test10Mb.db";
var uri = new Uri(address);
webClient.DownloadFile(uri, "D:\\Sample3.db");
//Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
string time = Convert.ToString(stopwatch.Elapsed);
double timeInSecond = TimeSpan.Parse(time).TotalSeconds;
int speed = 10240 / Convert.ToInt32(timeInSecond);
Console.WriteLine("Average Download speed: " + speed + "kbps");
}
推荐答案
这篇关于我们如何使用C#限制控制台应用程序中的网络带宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!