Silverlight中的连接速度测试
问题描述:
我想在Silverlight 3应用程序中添加某种“连接质量”指示器,以便让用户了解其连接速度。这可能是一个变成红色,黄色或绿色的图标,以提供用户应该期望的性能的基本概念。在Silverlight中测量连接速度的好方法是什么?Silverlight中的连接速度测试
答
我会开始一个Web请求,然后时间花了多长时间。例如:
public partial class Page:UserControl { DateTime started;
public Page()
{
InitializeComponent();
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
started = DateTime.Now;
client.DownloadStringAsync(new Uri("SomeKnownURI...", UriKind.Relative));
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
//error checking...
TimeSpan ts = DateTime.Now - started;
throw new NotImplementedException();
}
}