开发者

anyone have a simple implementation of an asynchronous web request that I can see?

开发者 https://www.devze.com 2023-01-14 07:28 出处:网络
I\'m looking to use an asynchronous web request in silverlight and would like to look at an example 开发者_如何转开发which isn\'t as confusing as the documentation on msdn.The secret of asynchronous m

I'm looking to use an asynchronous web request in silverlight and would like to look at an example 开发者_如何转开发which isn't as confusing as the documentation on msdn.


The secret of asynchronous method calls is that you provide a callback method (defined inline as lambda expression below) and then call the Async method which will immediately return. When the asynchronous operation finished, the callback method will be called.

var wc = new WebClient();

wc.DownloadStringCompleted += (sender, e) =>
{
    using (sender as IDisposable)
    {
        myTextBox.Text = e.Result;
    }
};

wc.DownloadStringAsync(new Uri("http://stackoverflow.com"));

var wc = new WebClient();

wc.DownloadStringCompleted += wc_DownloadStringCompleted;

wc.DownloadStringAsync(new Uri("http://stackoverflow.com"));

with

void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    using (sender as IDisposable)
    {
        myTextBox.Text = e.Result;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消