views:

391

answers:

1

I'd like to put some sort of "connection quality" indicator on a Silverlight 3 app that would give the user an idea of their connection speed. This could be an icon that turns red, yellow or green to give a basic idea of the performance the user should expect. What's a good way to measure connection speed in Silverlight?

A: 

I'd start a web request and then time how long it took. Something like:

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();
}

}

Erik Mork